How to Stop Ubuntu from Automatically Unmounting USB Drives When You Log Out

When you plug a USB flash drive or external hard drive into an Ubuntu Linux machine, the GNOME desktop environment automatically mounts it to your active user session (typically under /media/username/). This is convenient, but it comes with a strict security caveat: the moment you log out of your user account, Ubuntu assumes you are taking your data with you and automatically unmounts every single USB drive associated with your session.

If you are running a Plex server, a torrent client, or an SSH file share that relies on an external USB hard drive, simply clicking “Log Out” on the desktop will instantly sever the connection to the drive, crashing all of your background services.

To prevent Ubuntu from unmounting your drives when you log out, you must bypass the GNOME auto-mounter and mount the drive statically at the system level.

How to Stop Automatic Unmounting (fstab)

To make a USB drive persistent across all user sessions and logouts, you need to add it to the /etc/fstab file.

  1. Open your terminal application (Ctrl+Alt+T).
  2. First, find the UUID (unique identifier) of your USB drive by running:

sudo blkid

  1. Locate your USB drive in the output (e.g., /dev/sdb1) and carefully copy the UUID string (it will look something like UUID="1234-5678").
  2. Next, create a permanent folder where the drive will always live (outside of your user directory):

sudo mkdir /mnt/external_usb

  1. Open the file systems table in a text editor with root privileges:

sudo nano /etc/fstab

  1. Scroll to the very bottom of the file and paste your UUID along with the mounting instructions. For a standard FAT32/exFAT drive, it should look like this:

UUID=1234-5678 /mnt/external_usb auto defaults,nofail 0 0

  1. Save the file (Ctrl+O, Enter) and exit nano (Ctrl+X).

Now, reboot your machine. Your USB drive is now mounted by the core operating system, not by your GNOME desktop session. Because it is mounted at the system level, you can freely log in and out of your desktop account without the drive ever being unmounted.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.