This is an old revision of the document!
Table of Contents
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 certificate or generate a new one.
To check if you already have an SSH certificate that 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, you can proceed to step 2. If this file is empty or does not exist, it means that the key was never generated.
To generate the key you can use a key generator such as PuTTYgen, or command line. To generate the key via command line use the command:
ssh-keygen -t rsa -C "your_email@unibz.it"
To generate the key via PuTTygen follow the guidelines of the product.
Remember that you can also use another name for the file name. You can call the file gitlab_rsa if you prefer or anything else.
CONFIGURE GITLAB ONLINE
Login to GitLab and go to → Profile Settings → SSH Keys. In the field Key copy the contents of the file: id_rsa.pub generated in step 1. Once you click Add Key, you will see the key listed in your SSH Keys.
LOCAL GITLAB PROFILE
SINGLE GIT ACCOUNT
You have to configure your locally installed gitlab client to connect using the ssh key.
LINUX/MACOSX Inside a terminal, type the following: git config –global user.name “Firstname Lastname” git config –global user.email “your_email@unibz.it” git config –list
WINDOWS Inside your GIT bash command line, type the following: git config –global user.name “Firstname Lastname” git config –global user.email “your_email@unibz.it” 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@unibz.it
Try to checkout repo. Should you experience trouble check the contents of file: .ssh/config. You can manually insert: host gitlabhostname.unibz.it
MULTIPLE GIT ACCOUNTS
You can also have different gitlab 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"