You can do that by:
1- Using GnuPG
- Open the terminal.
- Use the cd command and ls command to navigate to the directory containing the file you want to password-protect.
- Once inside the directory, run the following command to encrypt your file:
gpg -c filename
- Finally, when prompted for a passphrase, type in one that's strong and easy to remember.
GnuPG will now create an encrypted file (with .gpg extension) in your current working directory. To access it, you'll need to decrypt it. For this, run the following command, and when prompted for a password, enter the one you used to encrypt the file and hit Enter:
gpg filename.gpg
GnuPG will return a decrypted version of the file in your current working directory.
2- Using zip
- Open the terminal and use the cd and ls commands to go into the directory with the files to encrypt.
- Enter the command in the following format to create a password-protected zip file:
zip --password preferred_password archive_file.zip filename1 filename2
Here, replace preferred_password with the password you want to use to encrypt the archive and archive_file.zip
with the file name you want to give to the resultant archive.
Now, when you want to access these files, unzip the archive and enter your password. Or, to do it via the terminal, run:
unzip archive_file.zip
Zip will now ask you for a password. Enter the password you set at the time of encryption and hit Enter to decrypt the file.
3- Using mcrypt
- Open the terminal, and using cd and ls, go into the directory that contains the file you want to encrypt.
- Enter the command below to list out all the supported encryption algorithms:
mcrypt --list
- Finally, encrypt your file using:
mcrypt -a algorithm_name filename
- When asked for a passphrase, enter it twice and hit Enter.
mcrypt will now encrypt your file and save it with the ".nc" extension. If you wish to open this file, you'll need to decrypt it. To do this, run:
mcrypt -d filename.nc
And then, enter the decryption passphrase.
Source