Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. wikipedia
In a nutshell, SSH protocol allows connecting to and authenticating remote servers and services. This protocol requires ssh keys which facilitates connecting to Github without providing username and password credentials.
It is always good practice to look before you leap.
At the command line type the following:
$ ls -al ~/.ssh
Note: DO NOT ENTER $ it simply signifies that you are at the command line.
The above lists the files in a directory named .ssh, if they exist. The following are default file names:
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub
- Execute this command adding your Github email address to create a key pair:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-
Press Enter to save the file to the default location when prompted. You have the option to save the file elsewhere.
-
Type in a passphrase or opt out by leaving it empty when prompted.
-
Confirm you passphrase.
$ eval "$(ssh-agent -s)"
You should see something like:
Agent pid xxxxx
That starts a ssh-agent background process.
- If your OS is macOS Sierra 10.12.2 or later update your ~/.ssh/config file with the following:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
See GitHub for more details.
- Add keys and store phrase to key chain.
$ ssh-add -K ~/.ssh/id_rsa
If you get an error see ssh-add:illegal option -K.
- View the contents of your public key.
$ cat ~/.ssh/id_rsa.pub
-
Copy the entire key.
-
Login in to GitHub.
-
Click on you profile photo.
-
Go to settings.
-
In the left sidebar click SSH and GPG Keys.
-
Choose New SSH key or Add SSH key.
-
Use the Title field to name your key.
-
Paste the key into the Key field.
-
Click ADD SSH Key.
-
Confirm your password if required.
You now have a secure SSH connection. You can forget about having to supply pesky username and password credentials.
WORTHY NOTE: The https protocol is less secure than SSH but, it is easier to configure and less likely to be blocked by a firewall or proxy. This means that the remote clone URLs work everywhere.