Search code examples
linuxgpgpugnupggpgme

Unable to generate gpg keys in linux


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


Solution

  • 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 [email protected]
      user$ gpg --export-secret-key -a -o myprivatekey.txt [email protected]
      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