Setup Github Login with SSH Key-Pair
Generate a new local SSH key-pair with ssh-keygen -t ed25519 -C "<your-github-account-email>"
for use with github. Just hit return to use the default key-file name. Do not enter a passphrase (just hit return) unless you want to type a passphrase every time you commit.
$ ssh-keygen -t ed25519 -C "mrwattz@gmail.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/daniel/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/daniel/.ssh/id_ed25519
Your public key has been saved in /Users/daniel/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:vO8SE+sfMY4/0IzFi/1n3F4rjjm5RcNf4ymHFdBC/og mrwattz@gmail.com
The key's randomart image is:
+--[ED25519 256]--+
| +=+. o|
| .o+o E.|
| ..o. . O|
| . oo .=B|
| S +o oo**|
| .+ o.==+|
| . +.o=..|
| o. .oo.o |
| o. ...o+. |
+----[SHA256]-----+
Check that the key files exist with ls -l ~/.ssh
.
$ ls -l ~/.ssh
total 24
-rw------- 1 daniel staff 411 Aug 3 13:53 id_ed25519
-rw-r--r-- 1 daniel staff 99 Aug 3 13:53 id_ed25519.pub
-rw-r--r-- 1 daniel staff 305 Aug 3 10:43 known_hosts
Check for the ssh configs file.
$ cat ~/.ssh/config
cat: /Users/daniel/.ssh/config: No such file or directory
If no .ssh/config
file exists, create it.
$ touch ~/.ssh/config
Edit the .ssh/config
file. Add the following content. Make sure the IdentityFile
ssh configuration parameter points to your PRIVATE ssh key located at ~/.ssh/id_ed25519
.
$ nano ~/.ssh/config
Host github.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
From https://wiki.ucar.edu/display/ral/Git+and+GitHub:
-
If you have an ssh-agent loaded with keys, connecting to github.com may indeterminately use one of the keys in the agent, possibly using the WRONG key. Thus the
IdentitiesOnly
ssh configuration parameter must be set toyes
in order to only use that Identity. -
GitHub does not support Usernames in ssh connections -- All connections use the username 'git', thus the
User git
ssh configuration parameter.
Make sure everything in the .ssh/config
file looks good using cat ~/.ssh/config
.
$ cat ~/.ssh/config
Host github.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Start the ssh-agent
app in the background, so we can add the new private key to it with eval "$(ssh-agent -s)"
.
$ eval "$(ssh-agent -s)"
Agent pid 45799
Add the private key file to the ssh-agent
with ssh-add ~/.ssh/id_ed25519
.
$ ssh-add ~/.ssh/id_ed25519
Identity added: /Users/daniel/.ssh/id_ed25519 (mrwattz@gmail.com)
Add the Public SSH Key to Your Github Account
View the content of the public SSH key with cat ~/.ssh/id_ed25519.pub
.
dwatts@ral-venus:~$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIwUefbpKsVBURfNFEmzaFH9AS9c9ejgWR8FQg/Z22Bi mrwattz@gmail.com
Copy the file contents and it to your github user accounts SSH Keys section at: https://github.com/settings/keys
You need to add the key two times, once as the Authentication key
and again for the Signing key
. Make sure to title the keys so you know what server they are for.
The server should now be setup with your git user and ready to roll!