11

I'm not able to generate GPG keys in linux

sudo gpg --gen-key      # This is the command to try to generate key

error

You need a Passphrase to protect your secret key.

gpg: problem with the agent: Timeout        
gpg: Key generation canceled.

Please let me know where I'm doing wrong

user2932003
  • 171
  • 2
  • 4
  • 14
  • Can you please try without sudo or directly with root login – Rupesh Mar 02 '15 at 04:13
  • gpg with sudo,please try with this command : sudo --preserve-env YOUR_COMMAND... – Rupesh Mar 02 '15 at 04:17
  • @rups thnx for quick reply, when do I execute without sudo I go below error You need a Passphrase to protect your secret key. gpg: cancelled by user gpg: Key generation canceled. – user2932003 Mar 02 '15 at 04:26
  • Have you try with sudo --preserve-env YOUR_COMMAND? – Rupesh Mar 02 '15 at 04:27
  • I got this with above command sudo --preserve-env gpg --gen-key sudo: invalid option -- '-' usage: sudo [-D level] -h | -K | -k | -V usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] – user2932003 Mar 02 '15 at 04:29
  • try with sudo -E YOUR_COMMAND – Rupesh Mar 02 '15 at 04:37
  • @rups i hv tried one more command sudo -E gpg --gen-key but getting same error gpg: problem with the agent: Timeout gpg: Key generation canceled. – user2932003 Mar 02 '15 at 04:38
  • FWIW I had the same problem and it was because gpg was prompting me for a password via pop up window (forgot about this), but I was sshing into the computer w/o xforwarding at the time. – syntheticgio Jun 19 '19 at 11:17

1 Answers1

15

Please check with this

1) Run the gpg-agent command:

gpg-agent --daemon --use-standard-socket --pinentry-program /usr/bin/pinentry-curses

2) Generate enough entropy

sudo rngd -r /dev/urandom

3) Finally run the gpg command to generate the key:

gpg --gen-key

please run all commands with non-root user only

Please login with same user,which is used to create gpg keys.

1.We will export both our public key and private key as follows:

  user$ gpg --export -a -o mypublickey.txt user@replaceurmail.com
  user$ gpg --export-secret-key -a -o myprivatekey.txt user@replaceurmail.com
  user$ ls my*

myprivatekey.txt mypublickey.txt

  1. Import keys with same user

    User$ gpg --import myprivatekey.txt
    
  2. now try decrypt with same user

saljuama
  • 2,906
  • 1
  • 20
  • 42
Rupesh
  • 1,636
  • 13
  • 18
  • once again thnx... Sm error I got....You need a Passphrase to protect your secret key. gpg: problem with the agent: Timeout gpg: Key generation canceled. – user2932003 Mar 02 '15 at 04:51
  • all above command without sudo I got below error...... gpg: cancelled by user gpg: Key generation canceled. – user2932003 Mar 02 '15 at 04:54
  • have check folder & it permission of ~/.gnupg or please create mkdir -p 700 ~/.gnupg – Rupesh Mar 02 '15 at 05:02
  • 1
    again I got same error...You need a Passphrase to protect your secret key. gpg: problem with the agent: Timeout gpg: Key generation canceled. – user2932003 Mar 02 '15 at 05:37
  • please check gpg agent running or not with this command : pgrep gpg-agent – Rupesh Mar 02 '15 at 05:54
  • It is running.....[xxxxx@woksmddev01 ~]$ pgrep gpg-agent 31084 31122 – user2932003 Mar 02 '15 at 06:20
  • 2
    Last try : 1. please kill all process of gpg-agent & clean ~/.gnupg folder then run " eval $(gpg-agent --daemon) " command. 2 check gpg-agent running or not using "pgrep gpg-agent" command. 3. please run "export GPG_TTY=$(tty)" command & then 4. gpg --gen-key – Rupesh Mar 02 '15 at 06:51
  • @rups...thnx lot man....now problem has been resolved...I have one more concern, I got error(gpg: decryption failed: No secret key) when do I decrypt the process sudo gpg -d -o xxxxxxx1 xxxxxxx.gpg – user2932003 Mar 02 '15 at 07:34
  • Have you try without sudo? – Rupesh Mar 02 '15 at 07:36
  • sm error without sudo....gpg: encrypted with RSA key, ID 4273F35C gpg: decryption failed: No secret key – user2932003 Mar 02 '15 at 07:53
  • what is output of gpg --list-keys – Rupesh Mar 02 '15 at 08:10
  • the output of above command /root/.gnupg/pubring.gpg ------------------------ pub 4096R/6197F9FC 2015-03-01 uid Akhilesh Chand (akhilesh) sub 4096R/4273F35C 2015-03-01 pub 2048R/3FA59C97 2015-03-02 uid akhilesh (ak) sub 2048R/EC0BCE3F 2015-03-02 – user2932003 Mar 02 '15 at 11:13
  • thnx a lot rups.......when do i export private key.... sudo gpg --export-secret-key -a -o myprivatekey.txt xxxxxxxxxxxxx@gmail.com gpg: WARNING: nothing exported – user2932003 Mar 02 '15 at 16:52
  • rups problem has been resolved thnx a lot for the same..... – user2932003 Mar 03 '15 at 05:16
  • same problem and it's still running >_ – Yan King Yin Mar 18 '18 at 17:42
  • I get this warning message when using --use-standard-socket; '''gpg-agent: WARNING: "--use-standard-socket" is an obsolete option - it has no effect''' – jeremiah Nov 28 '18 at 18:12
  • 2
    Under Debian to use rngd you need to install rng-tools package. – jeremiah Nov 28 '18 at 18:19
  • 1
    `sudo rngd -r /dev/urandom` was the only command needed for me to proceed with a key generation. – Neurotransmitter May 23 '19 at 11:20
  • 1
    I get this when I run the command `gpg-agent[3745]: WARNING: "--use-standard-socket" is an obsolete option - it has no effect gpg-agent[3745]: directory '/home/vscode/.gnupg/private-keys-v1.d' created gpg-agent: a gpg-agent is already running - not starting a new one` – Damian Jan 14 '22 at 01:01