How to Encrypt Disk in Linux Environment (2024)

With the growing number of data theft threats, it is important to ensure the information is properly protected. Though Linux is known to be the one of the most secure systems, it has its weak points which may open the door to hackers.

To secure the data on the disc you nominated to store the database you need to encrypt the disc. Encryption is the process of converting a plain text into ciphertext. You can encrypt a single disc, several partitions or the whole hard drive with help of a special algorithm. After encryption, it will be possible to access the disc only by using special password.

The main purpose of the hard drive encryption is to keep your information secure in case of devices being stolen or lost. However, if you host apps on your own server, encryption will help you feel more confident about your data security.

In Linux environment Linux Unified Key Setup (LUKS) is used for encrypting entire block devices, hard drive, SSDs and even removable storage drives. Full hard drive encryption is possible only during the installation of the Linux operating system. In this case it will encrypt both the swap space and system partitions. Post-installation encryption with help of the command line will help you encrypt your home directory and swap spaces separately.

Why it is necessary to encrypt swap spaces?

Encryption of swap spaces is necessary to keep secure sensitive information such as passwords. Swap space is the space on the hard drive used for virtual memory. When a Linux system is running out of RAM, the inactive pages are pushed to the swap space. The information moved there may contain such sensitive information as user names and passwords and thus it is necessary to have swap spaces encrypted as well.

Full hard drive encryption during installation of Ubuntu 22.10

The easiest way to encrypt the hard drive is to do this while installing Linux. This will ensure that everything runs without errors and all partitions get encrypted correctly.

To achieve full encryption of the hard drive you need to start encryption process during the Ubuntu system installation:

  1. After following the preliminary installation steps such as memory selection, keyboard layout, disk space, etc., you need to pay attention to the "Installation Type" step. Select there "Erase disk and install Ubuntu"
  2. Click "Advanced Features" button
  3. Select an option "Use LVM with new Ubuntu installation"
  4. Check a box "Encrypt the new Ubuntu installation for security"
  5. How to Encrypt Disk in Linux Environment (1)

  6. On the next step enter a security key and confirm it
  7. Optionally you can enable a recovery key and save it to the safe place elsewhere
  8. How to Encrypt Disk in Linux Environment (2)

  9. After clicking "Install Now" the disc will be encrypted during the installation
  10. To complete the installation reboot the system. Upon booting you will be prompted to provide the decryption key, the one you specified on Step 5 of this guide
  11. Type it in and press "Enter". After this your disc will be unlocked

Post installation encryption for Ubuntu 22.10

The recommended method of encryption of full disc space is LUKS encryption during the installation. However, if you already have the operating system installed, it is possible to encrypt home directory and swap spaces without reinstalling the operating system.

By default, home directory is the directory where all your files and documents are stored. Swap space is the space on the hard drive used for virtual memory. It can contain such sensitive information as user names and passwords, and thus it is also recommended to encrypt it.

Ubuntu provides a command-line tool to encrypt both swap spaces and home directory:

Home directory encryption

  1. Launch the terminal
  2. Install the software packages which provide encryption on Linux: ecrypt-utils and cryptsetup by running the following command:
    $ sudo apt install ecryptfs-utils cryptsetup
  3. Some of the files in your home directory might be rendered inaccessible if you are performing encryption while logged in with your own account. Thus it is necessary to create another privileged user to encrypt the home directory. For this purpose execute the following command:
    $ sudo adduser e_user
    where e_user is the name of your new user account
  4. Assign root privileges to e_user:
    $ sudo usermod -aG sudo e_user
  5. Log out and then log in with a new user e_user, which you created for encryption. Do not reboot!
  6. To take a look at the contents of the directory you are going to encrypt you can use the command:
    $ sudo ls -l ~directory_name
    where directory_name should be replaced with the name of the directory you are going to encrypt
  7. Start the encryption process by executing the following command:
    $ sudo ecryptfs-migrate-home -u directory_name
    where directory_name is the name of your home directory
  8. When you are prompted for the passphrase, provide the user account's login password and hit "ENTER"
  9. After the encryption has finished you need to log out of privileged user profile and log into your main profile and check if you can read and write files
  10. After logging into your regular profile and checking if you can read and write files you, you will need to record the encryption passphrase in the appeared pop up window and confirm it by clicking "Run this action now" button. This will open a Terminal window, where you will require to enter your password, after which a passphrase for your home directory will appear
  11. You can also reveal the recovery passphrase by executing the following command:
    $ sudo ecryptfs-unwrap-passphrase
  12. Save the recovery passphrase and keep it somewhere safe

Swap space encryption

  1. Check if you have swap space by executing the command
    $ swapon -s
  2. Then execute the command to encrypt the swap space:
    $ sudo ecryptfs-setup-swap
  3. That's it, the encryption has been completed

You will no longer need the privileged user you created for your home directory encryption. Thus you can remove it by following this command:
$ sudo deluser --remove-home e_user

We provided you with instructions for two encryption scenarios - during Linux installation and the post-installation one. We strongly recommend to use the first scenario as it's more easy and reliable. But if you need to encrypt an existing Linux installation, the second scenario will do the trick for you.

How to Encrypt Disk in Linux Environment (2024)

FAQs

How to encrypt a disk in Linux? ›

Disk Encryption in a Linux Environment
  1. Unmount the file system on the disk. ...
  2. Generate the key to be used by luksFormat . ...
  3. Initialize a LUKS partition and set the initial key. ...
  4. Open the LUKS partition on disk/device and set up a mapping name. ...
  5. Create an ext4 file system on the disk. ...
  6. Set parameters for the ext4 file system.

How do I encrypt a file locally in Linux? ›

File encryption on Linux

For on-the-fly encryption, you can use a tool called GnuPG. You can install it via terminal (sudo apt-get install gnupg) and run the command gpg -c filename to encrypt a file. You'll be asked to enter a passphrase.

Should you encrypt your hard drive Linux? ›

The main purpose of the hard drive encryption is to keep your information secure in case of devices being stolen or lost. However, if you host apps on your own server, encryption will help you feel more confident about your data security.

How do I encrypt my disk? ›

Enable Device Encryption
  1. Sign in to Windows with an administrator account.
  2. In the Settings app on your Windows device, select Privacy security > Device encryption or use the following shortcut: Device encryption. ...
  3. Use the toggle button to turn Device Encryption On.

How do I create a disk encryption? ›

Set up your disk encryption set

Search for Disk Encryption Sets and select it. On the Disk Encryption Sets pane, select +Create. Select your resource group, name your encryption set, and select the same region as your key vault.

How do I check if a disk is encrypted Linux? ›

Another way to validate the encryption status is by looking at the Disk settings section. This status means the disks have encryption settings stamped, not that they were actually encrypted at the OS level. By design, the disks are stamped first and encrypted later.

How to secure a file in Linux? ›

2. Encryption using GnuPG
  1. Access the terminal on your desktop.
  2. Makes use of the cd command and Is command to open the directory from which you want to choose a file for encryption.
  3. Once the directory is opened, enter this command: gpg -c filename.
  4. Lastly, you'll be asked to enter a passphrase.

How to encrypt the file in Unix command? ›

Encrypt/Decrypt Files in Linux using Ccrypt
  1. -e, –encrypt :Encrypt. This is the default mode. ...
  2. -d, –decrypt: Decrypt. ...
  3. -c, –cat: Decrypt one or more files to standard output. ...
  4. -x, –keychange: Change the key of encrypted data. ...
  5. -u, –unixcrypt: Simulate the old unix crypt command.
May 15, 2019

What is the Linux tool to encrypt files? ›

1. Tomb. Tomb is a free and open-source tool for easily encrypting and backing up files on GNU/Linux systems. It consists of a simple shell script that implements standard GNU tools alongside cryptsetup and LUKS (the Linux kernel's cryptographic API).

What is a disadvantage of encrypting a drive? ›

Drawbacks of full-disk encryption

If users forget their password and lose their recovery key, the device will be inaccessible to them, and they will be locked out just like an intruder. Data in transit isn't protected, so data shared between devices and through email is still vulnerable to hacking.

Does encrypting a disk slow it down? ›

And on modern hardware, encryption and decryption using the AES standard takes place in the CPU, which means that any impact on data transfer speeds is negligible.

Is it worth encrypting a hard drive? ›

The Importance of Encryption

You can choose an encryption program that will make it more difficult for the thief to access the information, and prevent anyone who might find your portable drive from accessing it easily.

Is there a way to encrypt disk without formatting it? ›

Yes, there is a way. The LUKS cryptsetup utility contains the reencrypt command that you can also use to encrypt your existing unencrypted root partition, i.e. without destroying the existing filesystem. That said, before performing such a conversion you should still backup your data.

How do I encrypt a drive file? ›

  1. Go to drive.google.com.
  2. At the top left, click New .
  3. Point to the arrow next to File upload. click Encrypt and upload file.

What is the disk encryption method? ›

Hard drive encryption uses a specific algorithm, or cipher, to convert a physical disk or logical volume into an unreadable format that cannot be unlocked by anyone without the secret key or password that was used to encrypt the drive. This prevents unauthorized people or hackers from accessing the information.

Does Linux have built-in encryption? ›

Linux devices can be encrypted in one of two ways: Full-disk encryption: Encrypting the block device before it is mounted on the system. File-based encryption: Encrypting only a folder or file using native filesystem features.

How to lock a hard drive on Linux? ›

How to password protect an external hard drive on Linux?
  1. Step 1: Install `cryptsetup` ...
  2. Step 2: Identify Your External Hard Drive. ...
  3. Step 3: Setup LUKS Encryption. ...
  4. Step 4: Open the Encrypted Device. ...
  5. Step 5: Create a Filesystem. ...
  6. Step 6: Mount the Encrypted Drive. ...
  7. Step 7: Access and Use the Drive.

How to encrypt a directory in Linux? ›

One way to encrypt a directory using a symmetric key in Linux is by using the "tar" and "gpg" utilities together. This will prompt you to enter and verify a passphrase, which will be used as the symmetric key.

Top Articles
Day-to-day Expenses - APK Download for Android
Google Software Engineer Levels: Roles and Expectations [With Salary]
Pga Scores Cbs
Alan Miller Jewelers Oregon Ohio
Myunlb
Calmspirits Clapper
Nj State Police Private Detective Unit
Apne Tv Co Com
Les Rainwater Auto Sales
Idaho Harvest Statistics
Swgoh Turn Meter Reduction Teams
Edicts Of The Prime Designate
Moving Sales Craigslist
How your diet could help combat climate change in 2019 | CNN
Reptile Expo Fayetteville Nc
Employee Health Upmc
15 Primewire Alternatives for Viewing Free Streams (2024)
Hdmovie2 Sbs
Weathervane Broken Monorail
Webworx Call Management
Ocala Craigslist Com
Experity Installer
Lawrence Ks Police Scanner
Craigslist Texas Killeen
Ff14 Laws Order
Gasbuddy Lenoir Nc
How to Draw a Bubble Letter M in 5 Easy Steps
ShadowCat - Forestry Mulching, Land Clearing, Bush Hog, Brush, Bobcat - farm & garden services - craigslist
Litter-Robot 3 Pinch Contact & DFI Kit
The Legacy 3: The Tree of Might – Walkthrough
Craigslist West Seneca
Kelsey Mcewen Photos
Viewfinder Mangabuddy
Muziq Najm
3400 Grams In Pounds
Wattengel Funeral Home Meadow Drive
Pensacola Cars Craigslist
Easy Pigs in a Blanket Recipe - Emmandi's Kitchen
Mugshots Journal Star
Inducement Small Bribe
St Vrain Schoology
What is 'Breaking Bad' star Aaron Paul's Net Worth?
Joblink Maine
Gander Mountain Mastercard Login
New Starfield Deep-Dive Reveals How Shattered Space DLC Will Finally Fix The Game's Biggest Combat Flaw
Dobratz Hantge Funeral Chapel Obituaries
York Racecourse | Racecourses.net
Diario Las Americas Rentas Hialeah
What Time Do Papa John's Pizza Close
Fallout 76 Fox Locations
Deviantart Rwby
ats: MODIFIED PETERBILT 389 [1.31.X] v update auf 1.48 Trucks Mod für American Truck Simulator
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 5629

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.