Book Image

GitLab Cookbook

By : Jeroen van Baarsen
Book Image

GitLab Cookbook

By: Jeroen van Baarsen

Overview of this book

Table of Contents (16 chapters)
GitLab Cookbook
About the Author
About the Reviewers

Adding your SSH key to GitLab

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.

How to do it…

To set up your SSH key, perform the following steps:

  1. Open GitLab and go to your account settings.

  2. Click on SSH.

  3. Click on Add SSH Key.

  4. To get information about your SSH key, enter the following command in your terminal. If you're using Windows, go to step 7:

    $ cat ~/.ssh/
  5. You should copy the entire content of the output in step 4, as shown in the following screenshot:

  6. If you're not using Windows, you can move to step 11.

  7. Open the Windows explorer and move to C:\Users\your_username\.ssh.

  8. Right-click on and click on Open.

  9. When asked for the program you want to use, select Notepad.

  10. Select the entire content of the file that contains the SSH key.

  11. 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.

  12. Now, click on Add Key.

How it works…

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.