Encrypt a USB Drive on Ubuntu with LUKS

A USB flash drive remains useful for moving files to a shared computer, carrying work offline or keeping a portable backup. On Ubuntu, the Linux Unified Key Setup (LUKS) standard can keep its contents unreadable while the drive is locked. LUKS provides disk encryption at rest; it does not merely hide files or depend on a particular USB manufacturer.

Australian shoppers can find familiar Kingston, SanDisk and other storage products at JB Hi-Fi, Officeworks and Harvey Norman. Recent USB-C laptops sold in Australia may also need an adapter for older Type-A drives, but the encryption method is otherwise the same. The setup works with ordinary flash memory and does not require hardware encryption built into the USB.

For commuters and students moving between home, campus or offices in Sydney, Melbourne, Brisbane and other Australian cities, a lost drive can contain more than convenience files. Under the Privacy Act 1988, Australian organisations may need to assess an incident involving personal information, making encrypted portable storage a sensible security control.

The commands below create a LUKS2 volume with cryptsetup, then format and mount its contents. They apply to Ubuntu Desktop and compatible Debian-based systems. Back up the original files first, because preparing the drive erases its existing partition layout.

Prepare the drive safely

Encryption is most useful when it covers the entire removable drive. A single encrypted partition spanning the full device prevents another partition from remaining readable. Before beginning, copy anything important to another drive and decide whether the USB will be dedicated to secure storage or will retain other partitions.

Identify the correct device instead of assuming it is /dev/sdb or another common name. Disconnect unrelated removable storage, then run:

lsblk -d -o NAME,SIZE,MODEL,TRAN
lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS,MODEL

Compare the capacity, model and connection type with the physical drive. In the examples, /dev/sdX represents the whole device and /dev/sdX1 represents its first partition. Replace those placeholders with the names shown by lsblk.

Ubuntu may have mounted the partitions automatically. Check the mountpoint column and unmount each one before continuing:

sudo umount /dev/sdX1

Repeat the command for any other mounted partition, or eject the drive through Files. If cryptsetup is missing, install it with sudo apt install cryptsetup. Never run the following destructive commands against an internal system disk.

Create a LUKS2 encrypted partition

Once the target is confirmed and unmounted, remove its old filesystem signatures and partition table. These commands replace the layout with a GUID partition table containing one partition across the whole drive:

sudo wipefs --all /dev/sdX
sudo parted -s /dev/sdX mklabel gpt
sudo parted -s -a optimal /dev/sdX mkpart primary 0% 100%

Run lsblk /dev/sdX and confirm that the newly created partition appears as /dev/sdX1 or under the equivalent name shown by Ubuntu. Repartitioning removes the old file-system structures, although it is not a forensic secure-erasure process for storage containing highly sensitive remnants.

Format that partition as a LUKS2 container:

sudo cryptsetup luksFormat --type luks2 /dev/sdX1

Confirm that existing data will be destroyed, then enter a strong passphrase twice. Avoid short PINs, reused passwords and predictable words. The passphrase protects the encryption key stored in the LUKS header, and Ubuntu cannot recover it if it is forgotten. Store the passphrase in a reputable password manager before adding important files.

Format and mount the protected volume

LUKS creates a locked container rather than a usable file system. Unlock it temporarily to create a device called secure_usb:

sudo cryptsetup open /dev/sdX1 secure_usb
lsblk -f /dev/sdX

The unlocked container should appear under /dev/mapper/secure_usb. Format that mapped device rather than the raw partition, because running mkfs on /dev/sdX1 would destroy the LUKS header:

sudo mkfs.ext4 -L "SecureUSB" /dev/mapper/secure_usb

Ext4 is a sensible choice for Ubuntu and other Linux systems. The encrypted container can also hold FAT32 or exFAT, which can simplify access after unlocking on another compatible machine, although LUKS itself remains a Linux-oriented format.

Mount the protected file system in a directory under the current user’s home folder:

sudo mkdir -p "$HOME/SecureUSB"
sudo mount /dev/mapper/secure_usb "$HOME/SecureUSB"
sudo chown "$USER":"$USER" "$HOME/SecureUSB"

The drive is now available at ~/SecureUSB and should appear in the Files sidebar. Ubuntu’s desktop mount service can also mount the mapped device with udisksctl mount -b /dev/mapper/secure_usb.

Unlock, use and lock the drive

After reconnection, find the LUKS partition again with lsblk and unlock it with the same mapping name:

sudo cryptsetup open /dev/sdX1 secure_usb
sudo mount /dev/mapper/secure_usb "$HOME/SecureUSB"

Check that the volume is active before copying files:

sudo cryptsetup status secure_usb

A second authorised person or a recovery passphrase can be added to another LUKS key slot:

sudo cryptsetup luksAddKey /dev/sdX1

Cryptsetup asks for an existing passphrase and then the new credential. This is useful for shared work devices, but a second key does not help if every passphrase has been lost.

Close the mapping whenever the drive is no longer needed:

sudo umount "$HOME/SecureUSB"
sudo cryptsetup close secure_usb

If the unmount command reports that the device is busy, close any file manager windows or applications using it and try again. Do not unplug the USB while its file system is mounted or the LUKS container remains open.

Use the graphical Disks route

Recent Ubuntu releases include GNOME Disks, which provides a graphical alternative to the terminal workflow. Open Disks from the applications menu and select the external drive by its model and capacity rather than by position in the list. If the package is absent, install it with sudo apt install gnome-disks.

For full-drive encryption, use the menu to erase the disk, create one partition using the available capacity, and open the partition’s format options. Choose the file system, enable the encryption control and select strong encryption where available. Enter a strong passphrase and complete the formatting process. The precise menu labels can vary between Ubuntu releases, and some versions provide only a compatibility encryption option.

Select the newly created encrypted volume in Disks and choose the unlock command. Enter the passphrase, mount it and use it like any other removable volume. A command-line check can confirm that the partition carries a LUKS header:

sudo cryptsetup isLuks /dev/sdX1

If Disks offers no encryption option, or you need precise control over the LUKS2 layout, use the cryptsetup method instead.

Keep the encrypted drive portable and recoverable

LUKS is natively supported across Linux distributions, including Ubuntu, but Windows and macOS do not provide built-in support for unlocking a LUKS2 container. Third-party utilities can handle some combinations of LUKS2, PBKDF2 and Argon2, but compatibility varies. Test the drive on every system it must open and keep an alternative transfer method for Windows or Apple computers.

The encrypted volume still needs a recovery plan. Keep the passphrase in a password manager, record that the drive uses LUKS, and store enough information to identify its partition without exposing sensitive files. A second key slot is useful for a designated backup administrator, although storing a recovery key on the same USB defeats much of its purpose. The Australian Cyber Security Centre treats portable storage as a potential data-exfiltration path, particularly when sensitive records travel between systems.

Encryption protects the contents only while the container is locked. Close the mapping after each session, use a screen lock on the Ubuntu computer and keep the USB somewhere secure when it is not needed. LUKS also does not replace a backup: damaged flash memory, accidental deletion or a forgotten passphrase can still cause data loss.

The practical takeaway is to verify the target by model and capacity, encrypt one partition spanning the entire drive with LUKS2, retain a tested passphrase recovery plan, and always unmount and close the protected volume before removing the USB.