Q:

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

A:

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

Import keys with same user
User$ gpg --import myprivatekey.txt

now try decrypt with same user

