Curriculum
Course: Git
Login
Text lesson

GitHub Add SSH

Copy the SSH Public Key

In the previous chapter, we generated an SSH key pair.

Now, use the clip < command to copy the public key to your clipboard:

Example

[user@localhost] $

clip < /Users/user/.ssh/id_rsa.pub

  • Go to GitHub, navigate to the top left corner, click on your profile, and select “Settings.”
  • Then select “SSH and GPG keys” and click the “New SSH key” button.
  • Enter a title, paste the public SSH key into the “Key” field, and click “Add SSH Key.”
  • You will be prompted to enter your GitHub password.
  • Once authenticated, you will see your new SSH key listed.

Test SSH Connection to GitHub

Now we can test our SSH connection to GitHub:

[user@localhost] $

ssh -T [email protected]
The authenticity of host ‘github.com (140.82.121.3)’ can’t be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added ‘github.com,140.82.121.3’ (RSA) to the list of known hosts.
Hi code7school-test! You’ve successfully authenticated, but GitHub does not provide shell access.

If the last line includes your GitHub username, you have successfully authenticated!

Add New GitHub SSH Remote

Now we can add a new remote to our Git repository using SSH.

First, obtain the SSH address from our repository on GitHub:

Next, use that address to add a new remote origin:

Example

[user@localhost] $

git remote add ssh-origin [email protected]:code7school-test/hello-world.git

Note: You can switch a remote origin from HTTPS to SSH using the command: git remote set-url remote-name [email protected]:username/repository.git.

Example

[user@localhost] $

git remote set-url origin [email protected]:code7school-test/hello-world.git