Skip to content

Instantly share code, notes, and snippets.

@cshtdd
Last active October 4, 2019 12:19
Show Gist options
  • Save cshtdd/957f184047f768e6c5939d54cdea7448 to your computer and use it in GitHub Desktop.
Save cshtdd/957f184047f768e6c5939d54cdea7448 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Start Export Process"
echo "Log into Keybase..."
keybase login
echo "Exporting your PGP keys..."
keybase pgp export -o keybase.public.key
keybase pgp export -s -o keybase.private.key
echo "Importing your Keybase keys..."
gpg -q --import keybase.public.key
gpg -q --allow-secret-key-import --import keybase.private.key
gpg --list-keys | grep '^pub\s*.*\/*.\s.*' | grep -oEi '\/(.*)\s' | cut -c 2- | awk '{$1=$1};1' > hash.key
echo "Generating RSA keys..."
gpg --export-options export-reset-subkey-passwd,export-minimal,no-export-attributes --export-secret-keys --no-armor `cat hash.key` | openpgp2ssh `cat hash.key` > id_rsa
chmod 400 id_rsa
ssh-keygen -y -f id_rsa > id_rsa.pub
echo "Cleaning up..."
rm *.key
echo "Success"
@nderjung
Copy link

nderjung commented Jan 29, 2017

Excellent script! However I believe this should take into account multiple keys for a single keybase user. Running this script on my own account resulted in a prompt 'ERROR Specify a key to export'. A simple fix is to enable a global -q flag for keybase commands. A more sophisticated script could prompt the user to choose a key before continuing with gpg imports and RSA key generation.

@marksharrison
Copy link

Very helpful script. Just a heads up, Homebrew recently moved keybase to Cask. Your writeup on tddapps.com for this script needs to change the prereq. install command to brew install git gpg monkeysphere && brew cask install keybase.

@cshtdd
Copy link
Author

cshtdd commented Sep 14, 2017

Thank you. I'll fix that

@javiergomezz
Copy link

Thanks for the script, but I tried it and doesn't work for me. The main problem if found is in generating RSA keys
with the "export-reset-subkey-passwd" option. Seems that it's not working anymore (https://dev.gnupg.org/T1753).
And also, generation of the "hash.key" file doesn't work. The "gpg --list-keys" output is a bit different now.

Fixing all this things, at the end, It cannot generate the public key file (id_rsa.pub) because the command "ssh-keygen -y -f id_rsa" is asking for a passphrase and don't like the one I provide.

Anyway, Thanks for your effort! :-)

@fairlygood
Copy link

I also found that this no longer works due to the changes to GPG, however I found the following tutorial helpful:

https://ashishchaudhary.in/pgp-to-ssh

@cshtdd
Copy link
Author

cshtdd commented Mar 26, 2018

I'll be updating the script soon. I'm setting up a new computer and I'll be taking notes of my progress. Thanks for your comments

@cshtdd
Copy link
Author

cshtdd commented Mar 26, 2018

This gist is outdated, please read the updated blogpost https://www.tddapps.com/2017/01/15/how-to-use-your-keybase-key-for-ssh/

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