How to add ssh key to gitlab accounts

Ari Nurcahya
3 min readDec 21, 2020

Hello everyone, good morning.

I’m trying to write this article using english, well. it might be ungrammatical, and maybe when you read it, you should be shocked because my bad english grammar, but I’ll try to keep using english version. lol

It has 3 days after I done my exam at my new company, because the HR told me to learn about the company’s products feature. and it is so hard because I’ve never learnt about the tax, but I enjoy it. and after done the exam my next step are setup the projects. git, trello, database, virtual host, etc, whatever. lol

for a few minutes I cannot add my ssh key from my machine to my gitlab account, so my senior told me to use http for cloning, and after that keep to try use ssh instead. okay that is my fault because sometimes I very nervous when someone looking up to me, so I cannot setup it, and cannot think clearly.

Generate SSH

You must create your ssh keys from your machine, I just create ssh keys at the default folder, at /Users/my-account-name/.ssh then type this code at your terminal.

ssh-keygen -t rsa -C "yourgitemail@email.com"

you will get a message to insert file name to your ssh key. default name is id_rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/nurcahyaari/.ssh/id_rsa):

after you inserted the ssh’s name you will get message to enter passphrase. I just make it as empty, and enter. end enter again because I didn’t type anytext for passphrase so when it told me to Enter same passphrase again I just typed Enter

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

then your terminal will print this

Your identification has been saved in test.
Your public key has been saved in test.pub.
The key fingerprint is:
SHA256:W4RhTmhYm85tspOqvtMEt4pK9+wmCTTiXDjMxp4ZNvE ari.nurcahya@fast-8.com
The key's randomart image is:
+---[RSA 3072]----+
| o..+ |
| . . o* o |
|+ + .o o . |
|.&.E.o . . |
|O Oo .+ S . |
| B o = o |
| o.=. + . |
|o +o+o . |
|o.++=+ |
+----[SHA256]-----+

congratulation you just make new ssh key, cheers

when you type l, or ll, or ls you will see a new ssh file

-rw-------    1 nurcahyaari  staff   2.5K Dec 21 09:34 test
-rw-r--r-- 1 nurcahyaari staff 577B Dec 21 09:34 test.pub

Registering SSH to your machine

after you created a new ssh key you must registering it to your machine.

  • Start your ssh-agent
eval $(ssh-agent -s)
  • Add your ssh key
ssh-add -K ~/.ssh/test
  • Open your SSH config file
nano ~/.ssh/config
  • Type this config
Host your_git_host
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/test
  • Save your config file by using ctrl + x
  • Check your ssh key
ssh-add -l

Insert your SSH Key to your Gitlab Account

  • First you must copy your public ssh key
pbcopy < ~/.ssh/test.pub
  • Go to gitlab, then go to Profile > keys
  • Paste your public key to key input, and you can add the title
  • Press Add key button
  • check your SSH by typing
ssh -T git@gitlab.com

where the gitlab.com is your gitlab email

  • when your ssh are correctly, the output will be
Welcome to GitLab, @nurcahyaari!

WoW, You have been adding your SSH key to your Gitlab

--

--