How to encrypt a file on Linux (and when you should)

Getty Photographs/Javier Zayas Pictures Your safety and privateness have each turn into critically vital. Companies usually are not the one entities that must preserve delicate data from prying eyes. You might need checking account particulars, contracts, wills, and different information in your desktop that needs to be locked behind a password, so solely you possibly … The post How to encrypt a file on Linux (and when you should) appeared first on Ferdja.

May 8, 2023 - 10:00
 1
How to encrypt a file on Linux (and when you should)

Many Yellow Padlocks On Yellow Background. One Of Them Open.

Getty Photographs/Javier Zayas Pictures

Your safety and privateness have each turn into critically vital. Companies usually are not the one entities that must preserve delicate data from prying eyes. You might need checking account particulars, contracts, wills, and different information in your desktop that needs to be locked behind a password, so solely you possibly can entry them.

Additionally: One of the best Linux laptops you should buy

However how do you do that, if Linux is your working system of selection? Imagine it or not, it is really fairly easy. I wish to present you two totally different strategies — one utilizing the command line and one which makes use of the built-in file supervisor — so you can also shield these vital paperwork. 

You are able to do this with nearly any kind of file (textual content, .docx, .odt, PDF, .jpg, otherwise you title it). One phrase of warning: Each strategies do require utilizing the command line. Nevertheless, the GUI technique solely requires that you simply use the command line to put in the required integration for the file supervisor.

Additionally: create hidden information in Linux (and what to not use them for)

With that mentioned, let’s get to the processes.

The command line technique of encrypting information

What you want: The one factor you want for this can be a operating occasion of Linux and a file to encrypt. That is it. 

The very first thing to do is open the terminal window out of your desktop menu. As soon as it is open, you may wish to generate a GPG key with the command:

You may be requested to enter your actual title and an electronic mail handle, then kind “O “to Okay the knowledge. After that, you kind/confirm a passphrase for the important thing.

Along with your key created, navigate to the folder housing the file to be encrypted. To illustrate the file is in ~/Paperwork. Change to that listing with the command:

We will use the gpg command to encrypt the file. For instance, we’ll encrypt the file zdnet_test with the command:

The -c possibility tells gpg the zdnet_test file is to be encrypted. You’ll then be requested to kind and confirm a password for the encrypted file. 

As soon as you’ve got encrypted the file, you may discover there are two information: zdnet_test and zdnet_test.gpg. The file with the .gpg extension is the encrypted file. At this level, you possibly can take away the preliminary take a look at file with the command:

Oddly sufficient, the GPG software caches passwords. Due to this, you (or anybody who has entry to your system) may decrypt the file with out having to kind the password with the command gpg zdnet_test. That is not protected. To get round this, we’ve to disable password caching for the GPG agent. To do that, create a brand new file with the command:

nano ~/.gnupg/gpg-agent.conf

In that file, paste the next strains:

default-cache-ttl 1
max-cache-ttl 1

Subsequent, restart the agent with the command:

echo RELOADAGENT | gpg-connect-agent

Now, whenever you (or anybody) sorts the decrypt command, gpg zdnet_test, the password immediate will seem. Till that password is efficiently entered, the contents of the file will stay encrypted. 

The GUI (Graphical Person Interface) technique of encrypting information

This technique is considerably extra environment friendly. 

1. Set up the required software program

Earlier than you employ the GUI technique, make sure that to care for Steps 1 and 4 above. You solely have to do that as soon as. After that, you may want to put in a chunk of software program with the command:

sudo apt-get set up seahorse-nautilus -y

In the event you’re utilizing a distribution primarily based on RHEL or Fedora Linux, that command can be:

sudo dnf set up seahorse-nautilus -y

As soon as put in, restart Nautilus with the command:

2. Open the Nautilus file supervisor

Now, open the file supervisor and navigate to the folder containing our zdnet_test file. Proper-click the file and choose the “Encrypt” possibility. 

The GPG key selector.

My GPG secret is listed and prepared for use.

Screenshot by Jack Wallen/ZDNET

3. Choose your encryption technique

Now you can both choose the GPG key you created earlier or simply use a passphrase for the encryption. In the event you choose to go the important thing route, make sure that to pick the important thing you created after which click on “OK.” You will not be prompted for a passphrase when you go this route. However when you choose to simply use a passphrase, you may be prompted to kind and confirm a brand new passphrase for the encrypted file.

The GPG key selector.

My GPG secret is listed and prepared for use.

Screenshot by Jack Wallen/ZDNET

4. Decrypt the file

With the file encrypted, you possibly can then decrypt it by right-clicking the encrypted file and deciding on “Open With Decrypt File.” After this step, you may be requested to call the decrypted file and click on “Save.” Then, for the encryption, you may be prompted to both kind the passphrase to your GPG key or the passphrase you added.

The Nautilus right-click menu.

Decrypting a file inside Nautilus.

Screenshot by Jack Wallen/ZDNET

Whichever technique you select, I might extremely suggest you take a look at (utilizing a take a look at file) to ensure it really works as anticipated earlier than you really encrypt an precise file you wish to shield. 

After you have the method down (and it really works as anticipated), it’s best to then be protected to take away the unencrypted file. In the event you go away the unencrypted file in your drive, it may be accessed by anybody who can log into your desktop.

Additionally: Pop!_OS has a sophisticated title but it surely makes utilizing Linux really easy

And that is the way you encrypt and decrypt a file on the Linux working system with out having to put in extra difficult quantity encryption instruments. 



The post How to encrypt a file on Linux (and when you should) appeared first on Ferdja.