GitHub SSH keys
To communicate with GitHub, you can use the protocol HTTPS (default) or the protocol SSH (recommended). The protocol SSH is a more secure method of logging into a remote server (GitHub). To use this protocol, you need to generate an SSH keys pair that consists in creating two long strings of characters: a public key and a private key. You can place the public key on any server (for instance GitHub), and then connect to the server using a device (your laptop) that has access to the private key.
To generate a new SSH keys pair proceed as follow:
- Create an account on GitHub at https://github.com/signup
- Open RStudio and click on:
Tools > Global options > Git/SVN
- Click on Create SSH Key, select ED25519 and then click on Create (you can omit the passphrase). This new SSH keys pair has been stored in
~/.ssh/
. - Click on View public key and copy it
- Go to the page https://github.com/settings/keys and click on New SSH key
- Choose a name for your key (e.g. your laptop name) and paste your public key.
- Finally click on Add SSH key
If you are on Ubuntu you might need to install ssh-askpass
:
sudo apt install ssh-askpass
Let’s test the SSH connection with GitHub. Open a terminal and run:
ssh -T git@github.com
When you first connect to GitHub (and to any remote server), you will be asked if you trust this server:
The authenticity of host '[92.168.45.3]:22' can't be established.
ED25519 key fingerprint is ...
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Just write yes
and press Enter
. This will add a line in the file ~/.ssh/known_hosts
that lists all your trusted servers.
Congrats! You can now communicate with GitHub using the SSH protocol.
From now, you need to use the SSH URL when connecting to a GitHub repo.
# SSH URL (use this one) ----
git@github.com:github_account/github_repo.git
# HTTPS URL ----
https://github.com/github_account/github_repo.git
N.B. If you lose your private SSH key you won’t be able to establish a connection with GitHub. You’ll need to delete your SSH key on GitHub and to create a new one.