Need simple process for File Encryption and decryption using gpg command in Linux
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need simple process for File Encryption and decryption using gpg command in Linux
Hello Group members..
I am Very new to Linux, was working on Unix for simple scripting.
Now We have a task to migrate the server from Unix to Linux.
We found that the crypt/encrypt commands are not available in Linux and we need to use GPG command instead.
I found the content from various websites is some what confusing.
Could you please let me know the simple steps for crypting/decrypting a file using gpg command(including key generation). we need to SFTP the crypted file to other server and decrypt the same there. I have other server which is unix server where we can not find gpg command.
It will be helpful for me If some body can provide end to end steps for using gpg with sample piece of code.
Thank you in advance.
You won't be able to encrypt or decrypt over SFTP. You'll need a proper interactive session for that. But you can transfer encrypted files over SFTP and then use an interactive session to decrypt. For what it's worth, SFTP already uses strong encryption, so I'm not sure what you aim to achieve given the information provided so far.
What kind of encryption are you talking about? If you are using a symmetric cypher, then just use -c to encrypt and -d to decrypt.
If you are talking about public key encryption, then you'll need a viable keyring on both machines. If that is the case which guide are you following and where are you stuck?
Hi,
Thank you for the explanation.
In the existing Unix process , by using crypt command files are getting encrypted and then are getting transferred to other systems through SFTP.
No we need to implement the similar process in Linux, hence I am trying to use gpg for encryption. For now we can leave about SFTP. My main aim is to encrypt the file.
I have already tried the below command to crypt the file , but it is giving the below error, could you please help me out.
gpg -c test_gpg.txt
error is like this :
gpg: cancelled by user
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of `test_gpg.txt' failed: Operation cancelled
gpg: WARNING: "--no-use-agent" is an obsolete option - it has no effect
gpg: cancelled by user
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of `[stdin]' failed: Operation cancelled
But I am able to encrypt the file through the below command:
Redirection to output file is not happening, only an empty file is getting created with the file name specified and the encrypted file with the same name as input file with extension.
Can we get the encrypted/decrypted out put file with the required name (should not be similar to input file).
Version of gpg is : gpg (GnuPG) 2.0.22
Planning for symmetric encryption only and as of now I am going with default Cypher, not giving any algo while crypting.
And I found that the default cypher algo is CAST5, am I correct?
Yes, the default cipher for GnuPG 2 is CAST5. As mentioned you can choose another cipher if you wish.
The file names should not matter if you are using redirects for input and output.
About GnuPG 2, there's the problem. gpg 2.x does not seem to run without a graphical environment, at least not as far as I have been able to determine. There are a lot of posts out on the web on the matter but they all come down to two options for attempted solutions, both of which have lots of complaints about not working. gpg 1.x still works on headless machines. One would almost suspect that gpg2 was made so very much harder to use on purpose to discourage its spread.
Therefore I would recommend posting your question about GnuPG 2.0.22 to the gnupg-users mailing list and see if you can get a solution from them. If you do find a way to do encryption using GnuPG 2.x on a headless machine please post your answer here as I think there are many that could benefit from it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.