GitHub account setup
In this course, we are using GitHub as an example, but other services such as GitLab and Bitbucket offer similar services.
Before starting to use GitHub, you need to create and configure an account. We will do this in this section.
Create a free GitHub account
If you don’t already have one, go to the GitHub website and create a free account.
Connect to GitHub
The 2 main ways to push data to GitHub are:
- using a token,
- using SSH.
There are alternative methods but you will have to look for information on your own:
- If you use Edge, there is an integration with GitHub since they are both owned by Microsoft.
- The GitHub Desktop application gives additional options to connect.
- If you use the GitHub app, it also gives authentication methods.
Using a token
A token can be generated directly within GitHub settings, which seems convenient. However, if you use a token, you will have to communicate with GitHub via HTTPS and enter your token whenever you push and pull to your GitHub directories. It is quite tedious.
If you have to use a token, here is the workflow:
- In the upper-right corner of any page on GitHub, click your profile photo, then click Settings.
- In the left sidebar, click Developer settings.
- In the left sidebar, under Personal access tokens, click Fine-grained tokens.
- Click Generate new token.
- Under Token name, enter a name for the token.
- Under Repository access, select which repositories you want the token to access.
- Under Permissions, select which permissions to grant the token.
- Click Generate token.
- Make sure to copy the token and save it to your computer.
When you push to GitHub, you will be asked for your username and password. Your username is your GitHub username and the password is your token.
Using SSH
An SSH key pair is a set of 2 files: the private key and the public key. You keep the private key securely on your machine—think of it as a key to open a lock—and you upload the public key to GitHub (or other places such as the Alliance clusters)—think of that as a lock.
Your private key allows to “open the lock” if it matches the public key.
People can see your public key, but they can’t generate the private key from it. Since you are the only one having the matching private key, you are the only one able to open that lock and log in securely—unless someone steals your private key (if they get access to your computer).
To add a level of safety, you can set a passphrase when you generate an SSH key pair. That way, to open that lock (public key), not only you need to have the matching private key, but you also need to enter the passphrase.
Generate SSH key pair
From Git Bash (Windows), Terminal (macOS), or your usual terminal emulator (Linux), run:
ssh-keygen
When prompted to
Enter a file in which to save the key
, you can pressEnter
to accept the default file name and location. If you have already created SSH key pairs,ssh-keygen
may ask to overwrite another pair. In that case, give your new key a custom name.When prompted to enter a passphrase, do so, then when prompted to enter it again, do so again.
SSH agent
If you do not want to enter the passphrase of your SSH key pair each time you push to GitHub, you can use an SSH agent to cache your passphrase.
Linux
For those using Linux, you can refer to the Arch Linux wiki section on SSH agent.
macOS
On macOS, you will be prompted for your passphrase the first time you use your key, but it will then be saved automatically in your keychain.
Windows
On Windows, you first add your SSH key to the SSH agent, then you can set your SSH agent to launch automatically when you open Git Bash.
Add the public key to GitHub
Here are the steps:
- Copy the content of your public key.
To do this, you can cat
its content to the terminal with (modify the file name if you used a custom name):
cat ~/.ssh/id_rsa.pub
Select the output and copy it.
- Go to your GitHub account, click your profile photo in the top right corner, then click Settings.
- In the Access section of the sidebar, click SSH and GPG keys.
- Click New SSH key.
- In the Title field, add a description for the key.
- Select authentication as the type of key.
- In the Key field, paste your public key.
- Click Add SSH key.
If you are having issue setting up SSH for GitHub, you can use a token today and look into this later.