Skip to content

Instantly share code, notes, and snippets.

@feynon
Created August 17, 2019 13:23
Show Gist options
  • Save feynon/3e1762cbf7026e24e5f412e026a27462 to your computer and use it in GitHub Desktop.
Save feynon/3e1762cbf7026e24e5f412e026a27462 to your computer and use it in GitHub Desktop.
Exporting a private GPG key from primary machine to another and setting it up on another by importing it and building trust. Last commands include steps to add it to your local git settings.
  • Exporting Keys from machine holding the primary key
hermisaurus@pop-os:~$ gpg --list-secret-keys
/home/shermisaurus/.gnupg/pubring.kbx
-------------------------------------
sec   rsa2048 2019-08-17 [SC]
      91E3CA9C218F5DA0214E8D78D6A03EC9488BECA2
uid           [ultimate] Ankesh Bharti (https://keybase.io/shermisaurus) <[email protected]>
ssb   rsa2048 2019-08-17 [E]



shermisaurus@pop-os:~$ gpg --export-secret-keys 91E3CA9C218F5DA0214E8D78D6A03EC9488BECA2 > privateKey.asc


  • Importing key and building trust on another machine
shermisaurus@elementary-os:~$ gpg --import 
.bash_history              Downloads/                 .pki/                      Videos/
.bash_logout               .gnupg/                    privateKey.asc             .vscode/
.bashrc                    .ICEauthority              .profile                   .writeas/
.cache/                    keybase_amd64.deb          Public/                    .Xauthority
.config/                   .local/                    snap/                      .xsession-errors
.dmrc                      Music/                     .sudo_as_admin_successful  .xsession-errors.old
Documents/                 Pictures/                  Templates/                 
shermisaurus@elementary-os:~$ gpg --import 
.bash_history              Downloads/                 .pki/                      Videos/
.bash_logout               .gnupg/                    privateKey.asc             .vscode/
.bashrc                    .ICEauthority              .profile                   .writeas/
.cache/                    keybase_amd64.deb          Public/                    .Xauthority
.config/                   .local/                    snap/                      .xsession-errors
.dmrc                      Music/                     .sudo_as_admin_successful  .xsession-errors.old
Documents/                 Pictures/                  Templates/                 
shermisaurus@elementary-os:~$ gpg --import privateKey.asc 
gpg: key D6A03EC9488BECA2: public key "Ankesh Bharti (https://keybase.io/shermisaurus) <[email protected]>" imported
gpg: key D6A03EC9488BECA2: secret key imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1
shermisaurus@elementary-os:~$ gpg --edit-key privateKey.asc 
gpg (GnuPG) 2.2.4; Copyright (C) 2017 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: key "privateKey.asc" not found: No public key
shermisaurus@elementary-os:~$ gpg --edit-key D6A03EC9488BECA2
gpg (GnuPG) 2.2.4; Copyright (C) 2017 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Secret key is available.

sec  rsa2048/D6A03EC9488BECA2
     created: 2019-08-17  expires: never       usage: SC  
     trust: unknown       validity: unknown
ssb  rsa2048/19008B41427C8532
     created: 2019-08-17  expires: never       usage: E   
[ unknown] (1). Ankesh Bharti (https://keybase.io/shermisaurus) <[email protected]>

gpg> trust
sec  rsa2048/D6A03EC9488BECA2
     created: 2019-08-17  expires: never       usage: SC  
     trust: unknown       validity: unknown
ssb  rsa2048/19008B41427C8532
     created: 2019-08-17  expires: never       usage: E   
[ unknown] (1). Ankesh Bharti (https://keybase.io/shermisaurus) <[email protected]>

Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)

  1 = I don't know or won't say
  2 = I do NOT trust
  3 = I trust marginally
  4 = I trust fully
  5 = I trust ultimately
  m = back to the main menu

Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y

sec  rsa2048/D6A03EC9488BECA2
     created: 2019-08-17  expires: never       usage: SC  
     trust: ultimate      validity: unknown
ssb  rsa2048/19008B41427C8532
     created: 2019-08-17  expires: never       usage: E   
[ unknown] (1). Ankesh Bharti (https://keybase.io/shermisaurus) <[email protected]>
Please note that the shown key validity is not necessarily correct
unless you restart the program.


  1. Setting up git on build machien to use with SSH and proper GPG Keys
shermisaurus@elementary-os:~/Documents$ gpg --list-secret-keys --keyid-format LONG
/home/shermisaurus/.gnupg/pubring.kbx
-------------------------------------
sec   rsa2048/D6A03EC9488BECA2 2019-08-17 [SC]
      91E3CA9C218F5DA0214E8D78D6A03EC9488BECA2
uid                 [ultimate] Ankesh Bharti (https://keybase.io/shermisaurus) <[email protected]>
ssb   rsa2048/19008B41427C8532 2019-08-17 [E]

shermisaurus@elementary-os:~/Documents$ git config --global user.signingkey D6A03EC9488BECA2
shermisaurus@elementary-os:~/Documents$ git clone [email protected]:xshermix/Spleetly.git
Cloning into 'Spleetly'...
Warning: Permanently added the RSA host key for IP address '13.234.210.38' to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
shermisaurus@elementary-os:~/Documents$ ls -al ~/.ssh
total 12
drwx------  2 shermisaurus shermisaurus 4096 Aug 17 18:32 .
drwxr-xr-x 18 shermisaurus shermisaurus 4096 Aug 17 18:33 ..
-rw-r--r--  1 shermisaurus shermisaurus 1326 Aug 17 18:34 known_hosts
shermisaurus@elementary-os:~/Documents$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shermisaurus/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/shermisaurus/.ssh/id_rsa.
Your public key has been saved in /home/shermisaurus/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:e6c8SoLDhSmIHIKv4IwT0T2qalKdDVe6UXzI4CTecbw [email protected]
The key's randomart image is:
+---[RSA 4096]----+
|    . +=..       |
|.. o = oB .      |

+----[SHA256]-----+
shermisaurus@elementary-os:~/Documents$ eval "$(ssh-agent -s)"
Agent pid 13120
shermisaurus@elementary-os:~/Documents$  ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/shermisaurus/.ssh/id_rsa: 
Identity added: /home/shermisaurus/.ssh/id_rsa (/home/shermisaurus/.ssh/id_rsa)
shermisaurus@elementary-os:~/Documents$ sudo apt-get install xclip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gir1.2-vte-2.91 libido3-0.1-0 libllvm6.0
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  xclip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 17.5 kB of archives.
After this operation, 52.2 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 xclip amd64 0.12+svn84-4build1 [17.5 kB]
Fetched 17.5 kB in 0s (56.1 kB/s)
Selecting previously unselected package xclip.
(Reading database ... 181464 files and directories currently installed.)
Preparing to unpack .../xclip_0.12+svn84-4build1_amd64.deb ...
Unpacking xclip (0.12+svn84-4build1) ...
Setting up xclip (0.12+svn84-4build1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
shermisaurus@elementary-os:~/Documents$  xclip -sel clip < ~/.ssh/id_rsa.pub          

Add SSH key to your GitHub profile under Settings> SSH and GPG keys and then proceed with linking gpg to git

shermisaurus@elementary-os:~/Documents$ git clone [email protected]:xshermix/Spleetly.git
Cloning into 'Spleetly'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 33 (delta 7), reused 16 (delta 2), pack-reused 0
Receiving objects: 100% (33/33), 7.02 KiB | 3.51 MiB/s, done.
Resolving deltas: 100% (7/7), done.
shermisaurus@elementary-os:~/Documents$ git config --global user.name "Ankesh Bharti"
shermisaurus@elementary-os:~/Documents$ git config --global user.email "[email protected]"

@feynon
Copy link
Author

feynon commented Aug 17, 2019

Would post a "gpg-ssh for dummies" blog post on my personal site and dev.to soon as I am enlightened with the diffrences, use and working of the same alongwith keybase.io .

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