2

I have just recently installed Ubuntu 22.04 on my computer, and I don't know much about Linux. I have a file that I'm trying to secure (only accessible by password, for example)

Does anybody know how can I do that?

cocomac
  • 3,394
Llexii
  • 23

2 Answers2

6

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

arximughal
  • 771
  • 2
  • 6
  • 22
  • Thank you for your answer, I do have a question: Do I have to encrypt the file again each time I decrypt to access it ? – Llexii Feb 27 '23 at 09:31
  • 1
    Yes @Llexii.... – Rishon_JR Feb 27 '23 at 10:35
  • I used zip -re command to zip a directory on Ubuntu 22.04 and supplied a password. However the file names inside the zip archive are clearly visible without a password, even though the password is required to open any file. Just a word of caution if file names are considered sensitive. – Guangliang Feb 28 '24 at 17:36
1

LibreOffice -- Save with Password

LibreOffice comes preinstalled on Ubuntu.

LibreOffice documents (such as Calc spreadsheets and Write documents) can be saved with a password. The contents will be encrypted using the AES-256-CBC algorithm. Once saved with a password, the document can only be opened by supplying the correct password; it is not possible to recover the password if forgotten.

LibreOffice is also able to use a GPG key if preferred.

AlexP
  • 10,197