In this tutorial, you will learn how to use VeraCrypt on Command Line to Encrypt Drives on Ubuntu. In our previous article, we discussed how to install and use VeraCrypt to encrypt drives on Ubuntu.
We used the VeraCrypt GUI method. In this article, we are going to learn how to use VeraCrypt on command line interface to achieve the same encryption.
How to Use VeraCrypt on Command Line to Encrypt Drives on Ubuntu
To run VeraCrypt in text user interface, just type
veracrypt and pass the -t/–text option.
The command line synopsis of the
veracrypt command is;
veracrypt [OPTIONS] COMMAND veracrypt [OPTIONS] VOLUME_PATH [MOUNT_DIRECTORY]
To learn more about VeraCrypt command line options, run
With VeraCrypt, you can create two types of volumes;
- VeraCrypt Outer Volume
- VeraCrypt Hidden Volume. This is like creating another volume within an encrypted volume for more security!
While creating each volume, you can choose to use an unused partition or just create a file-based volume to store your data.
Create VeraCrypt Outer Volume on Command Line
veracrypt command from the terminal and pass option -c/–create and of course the -t/–text option. Most of the options will be requested if you don’t specify them on the command line and thus the setup becomes interactive.
sudo veracrypt -t -c
When you run the command, you are prompted to choose the type of volume. In this case, we are going to setup a Normal volume.
Volume type: 1) Normal 2) Hidden Select : 1
Next, enter the volume path. For example, /dev/sdb1.
CAUTION: If you are encrypting a partition, ensure that there is no data in it or the data has been backed up and backup confirmed. The process will wipe the partition clean and you will all data, if any was stored in it.
Note that I have unused partition,
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part / sdb 8:16 0 4G 0 disk └─sdb1 8:17 0 4G 0 part sr0 11:0 1 1024M 0 rom sr1 11:1 1 1024M 0 rom
Thus, if you are using a partition, enter the device;
Enter volume path: /dev/sdb1
Define the Encryption as well as the hashing algorithms;
We choose the AES and SHA 512 as encryption and hashing algorithms respectively. You can also just press enter to accept the defaults.
Encryption Algorithm: 1) AES 2) Serpent 3) Twofish 4) Camellia 5) Kuznyechik 6) AES(Twofish) 7) AES(Twofish(Serpent)) 8) Camellia(Kuznyechik) 9) Camellia(Serpent) 10) Kuznyechik(AES) 11) Kuznyechik(Serpent(Camellia)) 12) Kuznyechik(Twofish) 13) Serpent(AES) 14) Serpent(Twofish(AES)) 15) Twofish(Serpent) Select : 1 Hash algorithm: 1) SHA-512 2) Whirlpool 3) SHA-256 4) Streebog Select : 1
Define the filesystem to format the volume with.
Filesystem: 1) None 2) FAT 3) Linux Ext2 4) Linux Ext3 5) Linux Ext4 6) NTFS 7) exFAT Select : 5
In this case, we are going with Linux Ext4.
- you need to set the password for encrypting outer volume.
- For PIM and keyfile path, press enter to set empty values.
- Next, type random numbers that can be use to improve the cryptographic strength of the encryption key. In this case, you are required to enter at least 320 random numbers.
Enter password: Enter STRONGPASSWORD Re-enter password: Re-Enter STRONGPASSWORD Enter PIM: Enter Enter keyfile path [none]: Enter Please type at least 320 randomly chosen characters and then press Enter: <PASTE OR TYPE 320 CHARACTERS HERE > Done: 100.000% Speed: 54 MB/s Left: 0 s The VeraCrypt volume has been successfully created.
To create the outer volume in non-interactive mode, run the command below;
sudo veracrypt -t -c --volume-type=normal /dev/sdb1 \ --encryption=aes --hash=sha-512 --filesystem=ext4 \ -p [email protected] --pim=0 -k "" --random-source=/dev/urandom
Create Hidden Volume within the Outer volume
Once the outer volume is created, you need to create the hidden volume within it. So repeat the above procedure but this time round;
sudo veracrypt -t -c
- Define the volume type as hidden.
- Enter volume path: /dev/sdb1, in our example.
- Define the size of the hidden volume.
- Set the encryption and hash algorithms
- Define filesystem type.
- Enter encryption password. Press enter for PIM and key file path.
- Generate and enter 320 random characters.
- If all is well, then your hidden volume should be successfully created.
Volume type: 1) Normal 2) Hidden Select : 2 IMPORTANT: Inexperienced users should use the graphical user interface to create a hidden volume. When using the text interface, the procedure described in the command line help must be followed to create a hidden volume. Enter volume path: /dev/sdb1 Enter hidden volume size (sizeK/size[M]/sizeG/sizeT/max): 1G Encryption Algorithm: 1) AES 2) Serpent 3) Twofish 4) Camellia 5) Kuznyechik 6) AES(Twofish) 7) AES(Twofish(Serpent)) 8) Camellia(Kuznyechik) 9) Camellia(Serpent) 10) Kuznyechik(AES) 11) Kuznyechik(Serpent(Camellia)) 12) Kuznyechik(Twofish) 13) Serpent(AES) 14) Serpent(Twofish(AES)) 15) Twofish(Serpent) Select : 1 Hash algorithm: 1) SHA-512 2) Whirlpool 3) SHA-256 4) Streebog Select : 1 Filesystem: 1) None 2) FAT 3) Linux Ext2 4) Linux Ext3 5) Linux Ext4 6) NTFS 7) exFAT 8) Btrfs Select : 5 Enter password: STRONGPASSWORDFORHIDDENVOLUME Re-enter password: STRONGPASSWORDFORHIDDENVOLUME Enter PIM: Enter Enter keyfile path [none]: Enter Please type at least 320 randomly chosen characters and then press Enter: <PASTE YOUR 320 CHARACTERS HERE > Done: 100.000% Speed: 256 MB/s Left: 0 s The hidden VeraCrypt volume has been successfully created and is ready for use. If all the instructions have been followed and if the precautions and requirements listed in the section "Security Requirements and Precautions Pertaining to Hidden Volumes" in the VeraCrypt User's Guide are followed, it should be impossible to prove that the hidden volume exists, even when the outer volume is mounted. WARNING: IF YOU DO NOT PROTECT THE HIDDEN VOLUME (FOR INFORMATION ON HOW TO DO SO, REFER TO THE SECTION "PROTECTION OF HIDDEN VOLUMES AGAINST DAMAGE" IN THE VERACRYPT USER'S GUIDE), DO NOT WRITE TO THE OUTER VOLUME. OTHERWISE, YOU MAY OVERWRITE AND DAMAGE THE HIDDEN VOLUME!
To create a hidden volume in non-interactive mode, run the command below;
sudo veracrypt -t -c --volume-type=hidden /dev/sdb2 \ --size=500M --encryption=aes --hash=sha-512 \ --filesystem=ext4 -p [email protected] --pim=0 \ -k "" --random-source=/dev/urandom
Mount the VeraCrypt Outer and Inner Volumes
Once you are done creating the volumes, you can now mount them and write your files or data to them as you wish.
To mount the outer volume, run the command below. When prompted for a password, use the password set for the outer volume above.
sudo veracrypt /dev/sdb1 /mnt/
Password wizard pops up to enter the outer volume encrypted password.
Once mounted, verify.
df -hT /mnt
Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/veracrypt1 ext4 3.9G 16M 3.7G 1% /mnt
To mount otvolume prompting only for its password:
sudo veracrypt -t -k "" --pim=0 --protect-hidden=no /dev/sdb1 /mnt/sdb1/
List the mounted VeraCrypt volumes.
1: /dev/sdb1 /dev/mapper/veracrypt1 /mnt/
To unmount the volume,
sudo veracrypt -d /dev/sdb1
To mount the hidden volume, run veracrypt command as shown above but this time, use the password defined for the hidden volume.
Seen how easy it is to use VeraCrypt on command line to encrypt your storage volumes? You can now create or put your sensitive data into the hidden volume. Enjoy the power of encryption.
That conclude our guide on how to use VeraCrypt on Command Line to Encrypt Drives on Ubuntu.