Gitlab public key authentication
I have used gitlab for quite a while as it provides me with quite some flexibility and have some additional advantages over it’s competitor github. I usually use public / private key authentication to push my codes onto the server. but after a fresh installation, I saw the following error when trying to work with gitlab.
$ git clone firstname.lastname@example.org:nuclearpasta/vehiclebooking.git Cloning into 'vehiclebooking'... email@example.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
As this was a fresh installation of my OS, my public key has changed so needed to update my keys to gitlab. So I navigated to my profile and checked out my public key.
So in my new Linux system, it does not have any previous keys so I had to generate
$ cd ~/.ssh/ $ ll total 12 drwx------ 2 reza reza 4096 Aug 21 12:41 ./ drwxr-x--- 26 reza reza 4096 Aug 26 10:57 ../ -rw-r--r-- 1 reza reza 142 Aug 21 12:41 known_hosts reza@legion:~/.ssh$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/reza/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/reza/.ssh/id_rsa Your public key has been saved in /home/reza/.ssh/id_rsa.pub The key fingerprint is: SHA256:SnWHOaiKzSCfq3XprK8tFyzmdH10/lzVBhFB1Nzithc reza@legion The key's randomart image is: +---[RSA 3072]----+ | o o**.| | * . o o +| | o = .. o.| | .++ o...o oE+| |. .. .o.So . +.| | o+*++... ... o .| | +=o*... o . . | | .o*. o | |..+*= | +----[SHA256]-----+ reza@legion:~/.ssh$ cat id_rsa id_rsa.pub known_hosts reza@legion:~/.ssh$ cat id_rsa.pub ssh-rsa AAAAB3NzaCp...[SNIP]...4E5tJmhvfzZVGoxoFQYz28= reza@legion
You now just have to copy the
id_rsa.pub which contains your public key to the gitlab so that you can authenticate.
Now if you re-try, you will get the following:
$ git clone firstname.lastname@example.org:nuclearpasta/vehiclebooking.git Cloning into 'vehiclebooking'... warning: You appear to have cloned an empty repository.