git tips and tricks — Add ssh key to gitlab

Privalov Vladimir
1 min readJan 8, 2020

--

Here I will show how to add ssh key to gitlab

First generate ssh key on host machine

ssh-keygen -t rsa

Now we will copy public key to gitlab profile. Go to gitlab.com, click on account photo, Settings and click the SSH keys on left toolbar

Print out the public SSH key

$ cat ~/.ssh/<key_file>.pub

Enter the content of the .pub file in the field Key and click Add key

Let’s add ssh key for gitlab to ssh config (source)

vim ~/.ssh/config

and add following lines

Host gitlab.com
Hostname gitlab.com
IdentityFile ~/.ssh/gitlab

Now clone some repo with ssh:

git clone git@gitlab.com:<user>/<repo>.git

--

--

No responses yet