Skip to content

Instantly share code, notes, and snippets.

@Avaq
Created November 4, 2014 12:25
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Avaq/e31ddbd427cffbeab734 to your computer and use it in GitHub Desktop.
Save Avaq/e31ddbd427cffbeab734 to your computer and use it in GitHub Desktop.
Exporting and importing GPG keys over SSH
ssh user@remote gpg --export-secret-key KeyId | gpg --allow-secret-key-import --import
# Based on key ID.
ssh user@remote gpg --export KeyId | gpg --import
# Based on key owner name.
ssh user@remote gpg --export -a KeyOwnerName | gpg --import
gpg --export-secret-key KeyId | ssh user@remote gpg --allow-secret-key-import --import
gpg --export KeyId | ssh user@remote gpg --import
@Jacob-Stevens-Haas
Copy link

Thanks! Any idea what error sending to agent: Inappropriate ioctl for device means when pushing public/private key?

@Avaq
Copy link
Author

Avaq commented Dec 9, 2022

I have not come across that. I'm sorry.

@aidenscott2016
Copy link

aidenscott2016 commented Feb 6, 2023

@Jacob-Stevens-Haas I also have this error. you must add the --batch parameter to the importing gpg. eg gpg --armor --export-secret-keys $KEY_ID | ssh aiden@10.0.4.46 gpg --allow-secret-key-import --import --batch gpg (GnuPG) 2.3.7

@hsxfjames
Copy link

I ran into several problems, the following should solve them:

  1. error sending to agent: No pinentry: just install pinentry package on target machine.
  2. error sending to agent: No such file or directory: just like @aidenscott2016 said, need to add --batch parameter with --import together.
  3. problem 2 still, run echo pinentry-mode loopback >> ~/.gnupg/gpg-agent.conf and restart gpg agent after gpgconf --kill gpg-agent should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment