How to add an SSH Key for GITLAB

GET/SET SSH KEY

You need an SSH key that resides on your workstation/notebook. You can use an already existing key or generate a new one.

To check if you already have an SSH key you have to check the file:

LINUX/MACOSX

.ssh/id_rsa.pub 

WINDOWS

%userprofile%\.ssh\id_rsa.pub

If this file contains an SSH-RSA key (open the file with a text editor), proceed to Configure the SSH key on gitlab.inf.unibz.it.

If this file is empty or does not exist, it means that the key was never generated so you have to generate it.

To generate an SSH key via command line open a LINUX/MACOSX terminal or WINDOWS Git BASH and run the command:

ssh-keygen -t rsa -C "your@email" -b 4096

When you're asked to “Enter a file in which to save the key,” select either the default location or a location you prefer and leave as name id_rsa (if this is your only RSA key) or setup a file name of your choice.GitLab Official Documentation

Windows Git Bash your rsa-key (~/.ssh/id_rsa) file MUST be called id_rsa.

You can also use a key generator such as PuTTYgen instead of using the terminal. Please refer to the guidelines of the product on how to create the RSA key and the location of the file.

CONFIGURE GITLAB ONLINE

Login to GitLab and go to your profile → Settings → SSH Keys.

In the field Key copy all the contents of the file: id_rsa.pub (or the specific name of your RSA key)

Choose a name to identify the key (ex. YourComputerName)

Click Add Key.

The key is listed in your SSH Keys.

Official Gitlab Documentation

GITLAB CLIENT CONFIGURATION

GLOBAL GIT ACCOUNT

You have to configure your locally installed gitlab client to connect using the ssh key.

Inside a terminal (Linux, MacOS)/Git BASH (Windows), type the following:

git config --global user.name "Firstname Lastname"
git config --global user.email "your@email"
git config --list

The last command should show the data you entered and is your gitlab global configuration.

This data is saved in the file ~/.gitconfig:

[user]
        name = Lastname Firstname
        email = your@email

Try to checkout repo. Should you experience trouble check the contents of file: .ssh/config. You can manually insert:

host gitlabhostname.unibz.it

LOCAL GIT ACCOUNT

You can also have different git accounts (with different RSA keys) for different hosts. You can keep a global user/email configuration and a local configuration for a specific repository. In the root of a repository, run:

git config user.name "Firstname Lastname"
git config user.email "your_other@email"
/var/www/wiki.inf.unibz.it/data/pages/auth/howto/sshkeygitlab.txt · Last modified: 2019/12/03 14:18 by apano
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0