Setup Access to GitLab
All of these steps are identical if you want to use platforms other than GitLab (e.g. GitHub), except for the “Configuration on GitLab” section.
Local configuration
You need to have git installed:
- MacOS: Install the XCode command line tools (try running
gitin your terminal and see if you get a popup) - Windows: Install git bash (or use WSL, if you know how to)
- Linux: Install git via your package manager of choice
In order for you to access a Git remote (like the EPFL GitLab), GitLab needs to validate that it is in fact you that is connecting to your repository.
The authentication is done via public key cryptography, which means we have to generate a private key (that only we know) and a public key (which we can give to GitLab).
If you are asked if you want to overwrite the key, select no. As a key already exists, we don’t want to overwrite it, skip the
ssh-keygenstep.
Generate a new key with the following command and follow the prompt (keep the name as ~/.ssh/id_ed25519 or whatever is suggested by the prompt):
ssh-keygen -t ed25519
In this example, we select the more modern
ed25519key instead ofRSA. But anRSAkey is totally fine too. Optional: Click here if you want to learn why.
Let’s view the public key that we will later use for GitLab:
cat ~/.ssh/id_ed25519.pub
Notice the
.pub. There is also a~/.ssh/id_ed25519, but that’s your private key, never copy it across computers or share it.If you also want to set up e.g. GitHub, it is safe to reuse this key.
Now, set your email and username for git. Replace the variables written with caps lock with your real email and name and enter the command:
git config --global user.name "FIRSTNAME LASTNAME"
git config --global user.email "FIRSTNAME.LASTNAME@epfl.ch"
Configuration on GitLab
We have now created a key locally, but the GitLab doesn’t yet know that.
The public key we generated has to be added to GitLab.
-
Sign in to the official EPFL GitLab: gitlab.epfl.ch
-
Go to:
Your profile icon(on the left) ->Preferences->SSH Keys(left) ->Add new key(top right) -
Paste your public key and add it to GitLab.
Example: Adding a new ssh key to GitLab
Use GitLab!
If you now clone your project using git, it automatically uses your key for authentication 🎉
Make sure to use the SSH syntax for cloning (with
git@nothttps://).Example:
git clone git@gitlab.epfl.ch:gnugen/just-do-git-lab.git
Example: Adding a new ssh key to GitLab