How to Encrypt File with Password Using GPG
Security is an very important side for each Linux consumer who needs to construct a safe device. From sending encrypted recordsdata or paperwork over the web to storing them on an area device, there exist more than a few answers for enabling report encryption tactics. You too can use a GPG or “GNU Privacy Guard” for encrypting a report or listing with a password in Linux.
This write-up will speak about methods to encrypt a report with password the use of GPG. Moreover, we can additionally exhibit the process of report encryption the use of the command-line and Seahorse Linux instrument. So, let’s get started!
Before leaping into the report encryption process, set up GPG in case you don’t have it already.
How to put in GPG in Linux
To set up GnuPG or GPG to your Linux device, at the start press “CTRL+ALT+T” after which sort the below-given command within the opened terminal:
$ sudo apt-get set up GnuPG
After putting in, transfer forward against the report encryption process.
Note: For the demonstration goal, we can percentage the encrypted recordsdata to every other consumer account in an effort to have a greater concept of the report decryption procedure.
How to encrypt a report with password the use of GPG thru command-line
In Linux-based techniques, you’ll be able to safe the recordsdata or paperwork with a password. For this goal, we can use GPG and display you methods to carry out the required operation during the command line.
The syntax of the gpg command for encrypting a report is given under:
Here, the “-c” choice is added to encrypt the report with the assistance of a symmetric cipher passphrase or password.
Now, at the start we can create a “samplefile.txt” report and upload some content material to it by means of executing the next “echo” command:
$ echo “This is linuxhint.com” > samplefile.txt
GPG used “CAST5” as an encryption set of rules within the older variations; alternatively, since model 2.1, the AES symmetric set of rules is embedded within the GPG tool. Three block ciphers at the moment are integrated in AES:
- “AES128” encrypts and decrypts a block of messages by using a 128-bit key period.
- “AES192” encrypts and decrypts a block of messages by using a 192-bit key period.
- “AES256” encrypts and decrypts a block of messages by using a 256-bit key period.
We have decided on the GPG “AES256” to encrypt the “samplefile.txt”:
$ gpg -c –cipher-algo AES256 ./samplefile.txt
Now, you are going to be requested to sort a passphrase. In the encryption procedure, the passphrase is used to encrypt the personal key of the consumer and give protection to it from any assault. So, make a selection a robust passphrase to safe the chosen report:
Re-enter your passphrase for the affirmation:
The error-free execution of the “gpg” command signifies that we have got effectively encrypted the “sampefile.txt” report:
After doing so, listing out the content material of your present operating listing and spot the encrypted “samplefile.txt.gpg” report:
Till this level, you’ve got encrypted the chosen report with a password the use of the GPG command. Now, take a look at its content material by means of executing the “cat” command:
The output will print out the encrypted type of the “samplefile.txt” report’s content material:
Next, execute the straightforward “gpg” command with the encrypted filename to generate its decrypted report:
You shall be requested to go into the “Passphrase” which was once used to encrypt the “samplefile.txt” report:
A “samplefile.txt” decrypted report shall be generated after coming into the passphrase. To take a look at its content material, write out the next command:
How to encrypt a report with password thru GUI
Most of the customers choose to make use of Linux GUI, because it lets them encrypt a report with a password the use of a couple of clicks. More particularly, the “Seahorse” is among the common Linux programs this is used for a similar goal.
Seahorse is a GNOME front-end program this is used for managing SSH, PGP, and the password associated with encrypted recordsdata. It was once launched as unfastened tool underneath the GPL 2.0 License. In the Seahorse program, the GPG is used for imposing the PGP reinforce and the GNOME keyring is helping to safe the passwords.
Now, execute the next command for putting in “seahorse-nautilus” bundle to your Linux device:
$ sudo apt-get set up seahorse-nautilus
The error-free output signifies that “Seahorse” is put in to your device. Now, make a selection the report which you need to encrypt with a password. In our case, we have now decided on the “testfile.txt” which is provide within the “Documents” Directory:
Next, click on at the decided on report and make a selection the “Encrypt” choice:
A pop-up conversation field will seem to your display, click on at the “Use a shared passphrase” solution to affiliate a password with the report encryption process:
Now, sort out a robust passphrase to finish the report encryption procedure:
Re-enter the added passphrase for the verification:
After doing so, you are going to see a brand new encrypted report having the similar filename as the unique one with the “.gpg” extension. For example, in our case, the “testfile.txt.pgp” is the encrypted report having a password:
To decrypt this “samplefile.txt.gpg” report, you’ve got to make a choice the “Open With Decrypt File” choice from its left-click menu:
Then, a passphrase window will seem to your display asking you to enter the passphrase which you’ve got used for encrypting the “testfile.txt” report:
After coming into the passphrase, a decrypted report shall be generated which is “testfile.txt” in our case:
Now, click on at the generated report and examine its decrypted content material for your textual content editor:
Conclusion
When it involves safety, encrypting recordsdata with passwords in Linux is a should. GPG lets you encrypt your recordsdata and paperwork prior to you ship them in ongoing verbal exchange. It additionally has a versatile key control device in addition to get entry to modules for quite a few public key directories. This write-up mentioned methods to encrypt recordsdata with a password the use of GPG. Moreover, we have now additionally demonstrated the process of report encryption the use of the command-line and Seahorse Linux instrument.