How to Stop Ubuntu from Automatically Mounting USB Drives

The Instant Connection

Modern Linux distributions, including Ubuntu, strive to provide a plug-and-play experience similar to Windows or macOS. When you plug a USB flash drive or an external hard drive into your computer, a background service (typically `udisks2`) immediately detects the hardware and automatically mounts the file system. It then usually opens a file manager window displaying the contents. While convenient for casual use, this automatic mounting is a severe security risk if you are dealing with potentially infected hardware, or a major annoyance if you are a developer plugging in drives specifically to format them or run low-level diagnostics using terminal tools.

Disabling Automount

To ensure you only interact with drives when you explicitly choose to and stop Ubuntu from automatically mounting USB drives upon connection, you must configure the GNOME desktop’s media handling behavior.

This setting is not exposed in the standard Settings app; it requires a quick terminal command using the GNOME configuration tool. Open your terminal by pressing Ctrl+Alt+T. To instruct the desktop environment to ignore new media, type the following command exactly: gsettings set org.gnome.desktop.media-handling automount false and press Enter. For maximum security, you should also disable the automatic opening of folders by typing: gsettings set org.gnome.desktop.media-handling automount-open false and pressing Enter. The next time you plug in a USB drive, nothing will happen visually. The drive will still appear in your disk utilities and the sidebar of your file manager, but you must manually click on it or use the mount command to actually access the files.

Get the best tech tips delivered straight to your inbox.

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