LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-08-2020, 07:06 AM   #1
Sum1
Member
 
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332

Rep: Reputation: 30
gpg decrypt file fails: No secret key


1. Digitalocean cloud-based CentOS7 machine using (GnuPG) 2.0.22 encrypts a file:

Code:
gpg -e --passphrase-file /home/abc/phrase.txt --batch -r john@johnsmith.com /home/abc/somefile.tar.gz
2. The public key on the cloud-based CentOS7 is then exported:

Code:
gpg --output public.gpg --armor --export john@johnsmith.com
3. The encrypted file, the pass-phrase file, and public key is then obtained and imported on Local Fedora 32 machine:

Code:
scp john@cloud-centos7:/home/abc/phrase.txt /home/john
Code:
scp john@cloud-centos7:/home/abc/somefile.tar.gz.gpg /home/john
Code:
scp john@cloud-centos7:/home/abc/public.gpg /home/john
Code:
gpg --import public.gpg
4. Attempts to decrypt the file using the passphrase file and without it fail:

Code:
gpg --passphrase-file /home/john/phrase.txt --batch -d --output /home/john/somefile.tar.gz /home/john/somefile.tar.gz.gpg
gpg: encrypted with 2048-bit RSA key, ID XXXXXXXXXXXXXXXXXX, created 2019-11-23
      "john smith <john@johnsmith.com>"
gpg: decryption failed: No secret key
[mhf@zxc ~]$ gpg -d --output /home/john/somefile.tar.gz /home/john/somefile.tar.gz.gpg
gpg: encrypted with 2048-bit RSA key, ID XXXXXXXXXXXXXXXXXX, created 2019-11-23
      "john smith <john@johnsmith.com>"
gpg: decryption failed: No secret key
I cannot determine why the imported gpg public key won't work and why gpg complains that a secret key is needed.

Thank you for reading.

Last edited by Sum1; 06-08-2020 at 07:09 AM.
 
Old 06-08-2020, 10:07 AM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,334

Rep: Reputation: Disabled
Quote:
Originally Posted by Sum1 View Post
Code:
gpg -e --passphrase-file /home/abc/phrase.txt --batch -r john@johnsmith.com /home/abc/somefile.tar.gz
That command does the following:
Code:
gpg -e
Tells gpg to encrypt a file,
Code:
--passphrase-file /home/abd/phrase.txt
using a passphrase found in the specified file, indicating we're using symmetric encryption,
Code:
--batch
in non-interactive mode,
Code:
-r john@johnsmith.com
encrypting the symmetric key using an asymmetric, public key associated with "john@johnsmith.com",
Code:
/home/abc/somefile.tar.gz
...and that's the file to be encrypted.
Quote:
Originally Posted by Sum1 View Post
2. The public key on the cloud-based CentOS7 is then exported:

Code:
gpg --output public.gpg --armor --export john@johnsmith.com
OK, so now anyone in possession of public.gpg can send "john@johnsmith.com" encrypted data. Not sure what that has to do with your file, though.
Quote:
Originally Posted by Sum1 View Post
3. The encrypted file, the pass-phrase file, and public key is then obtained and imported on Local Fedora 32 machine:

Code:
scp john@cloud-centos7:/home/abc/phrase.txt /home/john
Code:
scp john@cloud-centos7:/home/abc/somefile.tar.gz.gpg /home/john
Code:
scp john@cloud-centos7:/home/abc/public.gpg /home/john
Code:
gpg --import public.gpg
The Fedora machine now has a passphrase file, the public key belonging to "john@johnsmith.com", and a file encrypted with a session key that in turn is encrypted using the public key of "john@johnsmith.com".
Quote:
Originally Posted by Sum1 View Post
4. Attempts to decrypt the file using the passphrase file and without it fail:

Code:
gpg --passphrase-file /home/john/phrase.txt --batch -d --output /home/john/somefile.tar.gz /home/john/somefile.tar.gz.gpg
gpg: encrypted with 2048-bit RSA key, ID XXXXXXXXXXXXXXXXXX, created 2019-11-23
      "john smith <john@johnsmith.com>"
gpg: decryption failed: No secret key
[mhf@zxc ~]$ gpg -d --output /home/john/somefile.tar.gz /home/john/somefile.tar.gz.gpg
gpg: encrypted with 2048-bit RSA key, ID XXXXXXXXXXXXXXXXXX, created 2019-11-23
      "john smith <john@johnsmith.com>"
gpg: decryption failed: No secret key
Which is entirely as expected, as the file was encrypted using john@johnsmith.com's public key. John will obviously need his private key in order to decrypt it.

You're mixing two very different encryption concepts here: Symmetrically encrypting data using a passphrase (a shared key) that both parties will need to have, and using asymmetric encryption to encrypt a (symmetric and usually random) session key using the recipient's public key, which means only the recipient can decrypt the key that in turn is used to decrypt the data.

Really, the "--passphrase-file" and "-r" options are sort of mutually exclusive, or at least "--passphrase-file" should be redundant on a system with a decent pseudo-random number generator.

TL;DR: If you want to use symmetric encryption, specify "--symmetric" and drop the "-r". If you want to use asymmetric encryption, specify "-r recipient@domain.com" and remove "--passphrase-file".
 
1 members found this post helpful.
Old 06-08-2020, 10:36 AM   #3
Sum1
Member
 
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Ser Olmy View Post
TL;DR: If you want to use symmetric encryption, specify "--symmetric" and drop the "-r". If you want to use asymmetric encryption, specify "-r recipient@domain.com" and remove "--passphrase-file".
Thank you, Ser Olmy! A great beginner's walk through the foothills of cryptography mountain. I've got to make some more notes from the gnupg documentation so I don't find myself mixing symmetrical vs asymmetrical methods and procedures.
Kind regards.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mutt unable to decrypt emails "Could not decrypt PGP message" frddbbbl Linux - Software 3 07-25-2019 10:48 AM
gpg / gpg-agent -- Can't connect to /root/.gnupg/S.gpg-agent jrtayloriv Linux - Security 9 06-03-2019 10:06 AM
[SOLVED] How can I decrypt GPG file that encrypted with my lost private key ? mesuutt Linux - General 4 12-17-2011 11:07 AM
GPG: Bad session key gpg between gpg on linux and gpg gui on windows XP konqi Linux - Software 1 07-21-2009 09:37 AM
GPG Data, Secret Key but no Public Key? Aeiri Linux - Software 5 07-20-2004 06:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration