Today we will learn about how to connect to GitHub using the Secure Shell Protocol (SSH), which provides a secure channel over an unsecured network. With the help of SSH keys, we can connect to GitHub without providing our personal access (username and password) at each visit.
An SSH key is an access credential for the SSH (Secure Shell) network protocol. SSH is used for remote file transfer, network management, and remote operating system access. SSH keys always come in pairs, and every pair is made up of a private key and a public key.
- Public key – Everyone can see it, no need to protect it. (for encryption function)
- Private key – Stays in computer, must be protected. (for decryption function)
Open Git Bash
ls -al ~/.sshto see if existing SSH keys are present. Here you can see that I already have some SSH Keys.
1) If there is no key then generate a new SSH key
$ ssh-keygen -t ed25519 -C "firstname.lastname@example.org"
and this will generate a new SSH key:
Generating public/private ed25519 key pair.
2) When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/c/Users/you/.ssh/id_ed25519): [Press enter]
3) At the prompt, type a secure passphrase, press enter or you can give your passphrase.
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
4) Then you will get something like this:
Your identification has been saved in (/c/Users/you/.ssh/id_ed25519)
Your public key has been saved in (/c/Users/you/.ssh/id_ed25519)
- Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
- You will get your unique Agent pid.
Agent pid 59566
$ ssh-add ~/.ssh/id_ed25519
- You will get something like:
Identity added: /c/Users/you/.ssh/id_ed25519 (email@example.com)
- Copy the SSH public key
$ clip < ~/.ssh/id_ed25519.pubto your clipboard.
- From your GitHub Account go to Settings.
- In the user settings sidebar, click SSH and GPG keys.
- Click the New SSH Key or Add the SSH Key.
- In the Title field, add a descriptive label for the new key.
- Paste your key into the Key field.
- Click Add SSH Key.
- If prompted, confirm your GitHub password.
1) Open Git Bash
2) Enter the following:
$ ssh -T firstname.lastname@example.org
3) You may see a warning like this:
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
4) Verify the message by typing yes:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Thanks for reading this post. Stay tuned for more.
You can find me here also.