{"id":47172,"date":"2024-09-05T15:12:18","date_gmt":"2024-09-05T15:12:18","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47172"},"modified":"2025-01-28T07:14:58","modified_gmt":"2025-01-28T07:14:58","slug":"share-usb-ubuntu-lan","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/09\/share-usb-ubuntu-lan\/","title":{"rendered":"How to Share your USB Device in Ubuntu 24.04 over LAN"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-45859\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/usb-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a> This tutorial shows how to share your USB device, e.g., USB mouse\/keyboard, USB drive, webcam, and speaker, in Ubuntu so you can access remotely from other computers\/laptops. Linux Kernel includes a command line tool called USB\/IP, allowing to share USB devices between computers with their full functionality. So, a computer can use remote USB devices as if they were directly attached. If you just want to share USB mouse &amp; keyboard between computers, then <a href=\"https:\/\/ubuntuhandbook.org\/index.php\/2021\/06\/setup-barrier-share-mouse-keyboard-between-computers\/\" target=\"_blank\" rel=\"noopener\">Barrier<\/a> is a good choice. But for webcam, usb drive, printer (through it usually has option to do the job), and other general USB devices, this tutorial will show you how.<\/p>\n<p><!--more--><\/p>\n<h3>Step 1: Install the USB\/IP kernel tool<\/h3>\n<p>First of all, press <code>Ctrl+Alt+T<\/code> on keyboard to open up a terminal window. When terminal opens, run command to <strong>install the Linux kernel tools<\/strong>:<\/p>\n<pre>sudo apt install linux-tools-$(uname -r)<\/pre>\n<p>This command installs the kernel tools for current Kernel version. As Ubuntu updates its kernel regularly, you may need to re-run this command again for newer kernels. <a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/apt-linux-tools.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47173\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/apt-linux-tools-700x326.webp\" alt=\"\" width=\"610\" height=\"284\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/apt-linux-tools-700x326.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/apt-linux-tools-300x140.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/apt-linux-tools.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 2: Share USB devices at run-time<\/h3>\n<p>If you just want to try out this method, that works until reboot or you manually disable it, then run the commands below one by one. <strong>1. First, load the USB\/IP specific kernel modules<\/strong>. On the host computer with the USB devices connected, you need to first load the <code>usbip_core<\/code> and <code>usbip_host<\/code> kernel modules. To do so, open terminal (Ctrl+Alt+T) and run command:<\/p>\n<pre>sudo modprobe usbip_core<\/pre>\n<pre>sudo modprobe usbip_host<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-47174\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules.webp\" alt=\"\" width=\"674\" height=\"424\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules.webp 674w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules-300x189.webp 300w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/a> <strong>2. Then, run the daemon.<\/strong> There&#8217;s a <code>usbipd<\/code> command for running the server daemon, which by default listen on TCP port <strong>3240<\/strong>. To start the daemon, simply open terminal and run command:<\/p>\n<pre>usbipd &amp;<\/pre>\n<p>If port 3240 is in use, or you want to listen on another port, then use <code>usbipd --tcp-port 1234 &amp;<\/code> (replace number 1234) instead. <strong>3. Next, list all USB devices on computer,<\/strong> for the information, such as bus-id, vendor ID and product ID.<\/p>\n<pre>usbip list -l<\/pre>\n<p>In the output, you need to <strong>remember the bus-id<\/strong> (usually 1-1, 1-2, &#8230;) for the USB device you want to share. <strong>Finally, bind the USB device<\/strong> so it can&#8217;t be access remotely (replace bus-id <code>1-1<\/code> with yours).<\/p>\n<pre>sudo usbip bind -b 1-1<\/pre>\n<p>It should outputs something looks like &#8220;bind device on ***: complete&#8221;. However, for USB keyboard\/mouse, if you move or use the devices on host before connecting from remote, the bind may fail. And, to stop sharing the USB device, use command:<\/p>\n<pre>sudo usbip unbind -b 1-1<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-server.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47175\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-server-700x515.webp\" alt=\"\" width=\"610\" height=\"449\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-server-700x515.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-server-300x221.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-server.webp 738w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 3: Access the USB Device from Remote Machine<\/h3>\n<p>For the client machines, you also have to install the USB\/IP tool. See step 1 for Linux, and go to <a href=\"https:\/\/sourceforge.net\/projects\/usbip\/files\/usbip_windows\/\" target=\"_blank\" rel=\"noopener\">this page for Windows<\/a> (not tested). Then, you have to load the <code>vhci_hcd<\/code> kernel module by running command:<\/p>\n<pre>sudo modprobe vhci_hcd<\/pre>\n<p>Finally, list accessible remote USB devices:<\/p>\n<pre>sudo usbip list -r 192.168.0.104<\/pre>\n<p>And, attach the remote USB via command:<\/p>\n<pre>sudo usbip attach -r 192.168.0.104 -b 1-1<\/pre>\n<p>Here replace <code>192.168.0.104<\/code> with yours host IP, and replace <code>1-1<\/code> according which bus-id you shared. If everything goes well, you should now be able to use the remote USB device just like directly attached. <a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-47176\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind.webp\" alt=\"\" width=\"654\" height=\"365\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind.webp 654w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-300x167.webp 300w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a> To disconnect remote USB, use command to first list all connected:<\/p>\n<pre>sudo usbip port<\/pre>\n<p>Then, run command to detach (replace <code>00<\/code> according to last command output).<\/p>\n<pre>sudo usbip detach -p 00<\/pre>\n<h3>Enable USB Device Sharing on Startup<\/h3>\n<p>If the previous steps work good, and you want to make it permanent, then you can write rules to auto-load the kernel modules, auto-start the daemon, and auto-bind the USB device. <em><strong>NOTE:<\/strong> In the steps below, I will use <code>gnome-text-editor<\/code> (Gnome Default) to create &amp; edit conf file. You may replace it with <code>gedit<\/code> for 22.04 and earlier, <code>mousepad<\/code> for XFCE desktop, or <code>nano<\/code> text editor (Ctrl+S to save, Ctrl+X to exit) that works in most desktop environments.<\/em> <strong>1.<\/strong> First, auto-load the kernel modules on system boot by creating a custom conf file via command (Ctrl+Alt+T):<\/p>\n<pre>sudo gnome-text-editor \/etc\/modules-load.d\/usbip.conf<\/pre>\n<p>When file opens, just add the 2 lines below and save:<\/p>\n<pre>usbip_core\r\nusbip_host<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules-config.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47177\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules-config-700x340.webp\" alt=\"\" width=\"610\" height=\"296\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules-config-700x340.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules-config-300x146.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-modules-config.webp 752w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a> <strong>2.<\/strong> Then, auto-run the <code>usbipd<\/code> daemon by creating a systemd service via command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/systemd\/system\/usbipd.service<\/pre>\n<p>When file opens, add the lines below and save:<\/p>\n<pre>[Unit]\r\nDescription=USB\/IP server\r\nAfter=network.target\r\n\r\n[Service]\r\nExecStart=\/usr\/bin\/usbipd\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>Finally, <strong>run command to enable &amp; start the service<\/strong>:<\/p>\n<pre>sudo systemctl enable --now usbipd.service<\/pre>\n<p>NOTE: The service may fail to start until system reboot, as you already run the daemon in step 2-2. <a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbipd-service.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47178\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbipd-service-700x379.webp\" alt=\"\" width=\"610\" height=\"330\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbipd-service-700x379.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbipd-service-300x162.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbipd-service-768x415.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbipd-service.webp 817w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a> <strong>3.<\/strong> Finally, create a service to auto-bind the USB device your want to share. To do so, run command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/systemd\/system\/usbip-bind@.service<\/pre>\n<p>When file opens, add the lines below and save.<\/p>\n<pre>[Unit]\r\nDescription=USB-IP Binding on bus id %I\r\nAfter=network-online.target usbipd.service\r\nWants=network-online.target\r\nRequires=usbipd.service\r\n#DefaultInstance=1-1\r\n\r\n[Service]\r\nType=simple\r\nExecStart=\/usr\/bin\/usbip bind -b %i\r\nRemainAfterExit=yes\r\nExecStop=\/usr\/bin\/usbip unbind -b %i  \r\nRestart=on-failure\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>Next, you need to <strong>run command to enable &amp; start the service<\/strong>:<\/p>\n<pre>sudo systemctl enable --now usbip-bind@1-1.service<\/pre>\n<p>In this command, replace <strong>1-1<\/strong> according to which bus-id of the USB device you want to share. <a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-service.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47179\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-service-700x543.webp\" alt=\"\" width=\"610\" height=\"473\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-service-700x543.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-service-300x233.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-service-768x596.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/09\/usbip-bind-service.webp 834w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a> When done, restart your computer and try to attach from remote computer.<\/p>\n<h3>Undo:<\/h3>\n<p>To undo the last step, first open terminal (Ctrl+Alt+T) and run command to disable the services (also replace 1-1 accordingly):<\/p>\n<pre>sudo systemctl disable --now usbip-bind@1-1.service<\/pre>\n<pre>sudo systemctl disable --now usbipd.service<\/pre>\n<p>Then, remove the 3 config files, though the service files do not function until you re-enable them:<\/p>\n<pre>sudo rm \/etc\/systemd\/system\/usbip-bind@.service<\/pre>\n<pre>sudo rm \/etc\/systemd\/system\/usbipd.service<\/pre>\n<pre>sudo rm \/etc\/modules-load.d\/usbip.conf<\/pre>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to share your USB device, e.g., USB mouse\/keyboard, USB drive, webcam, and speaker, in Ubuntu so you can access remotely from other computers\/laptops. Linux Kernel includes a command line tool called USB\/IP, allowing to share USB devices between computers with their full functionality. So, a computer can use remote USB devices [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":45859,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1317,2211],"class_list":["post-47172","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-network","tag-usb"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=47172"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47172\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/45859"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}