In order for GitLab to know who we are and check whether we are authorized to commit certain code, we use our SSH key. The combination of the public key and the private key can tell GitLab that we are authorized, and GitLab will allow the operation to be performed.
To set up your SSH key, perform the following steps:
Open GitLab and go to your account settings.
Click on SSH.
$ cat ~/.ssh/id_rsa.pub
You should copy the entire content of the output in step 4, as shown in the following screenshot:
Right-click on id_rsa.pub and click on Open.
When asked for the program you want to use, select Notepad.
Select the entire content of the file that contains the SSH key.
We now paste the content of the SSH key into the form in your GitLab instance. You can name the SSH key anything you want. It is recommended that you name it after the computer it came from. This way, it will be easier to know which key belongs to which machine. If you leave the name field empty, GitLab will generate a name for you.
Now, click on Add Key.
In order to make Git aware of your SSH key, you need to add the public portion of the key to GitLab. When you add the SSH key to GitLab, it will put the key for the Git user in the
authorized_keys file on the GitLab server.
Whenever you will execute a Git command that will communicate with GitLab, it will check the permissions you have against your own user account.
One thing to remember is that you can only use one SSH key for one account, as it will be account-bound.