Fix for Gitlab Permission denied publickey

import Image from ‘@components/Image.astro’

This tutorial explains about solution for [email protected]: Permission denied (publickey).

Gitlab is a cloud hosting for managing git repositories.

When you are working with source code repositories, You need to clone code, add/change code, and push changes to the gitlab repository.

When you are pushing changes to GitLab using the git push command, It gives the following error.

[email protected]: Permission denied (publickey).

B:\waste\node-unittest.git>git push gitlab --mirror
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The error says you don’t have access rights from your machine to the GitLab repository.

You need to create a public key with a password and copy the ssh keys to gitlab dashboard..

Solution for [email protected]: Permission denied (publickey)

Following are steps

  • Open the Terminal or command prompt
  • Run the below command to generate
ssh-keygen -t ed25519 -C "[email protected]"

On entering the command, It asks for a password and repeats password to set it

Here is an output

B:\work>ssh-keygen -t ed25519 -C "[email protected]"
Generating public/private ed25519 key pair.
Enter the file in which to save the key (C:\Users\user/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\user/.ssh/id_ed25519.
Your public key has been saved in C:\Users\user/.ssh/
The key fingerprint is:
SHA256:asdwe+asdfwerwwerehash [email protected]
The key's randomart image is:
+--[ED25519 256]--+
| ...sadfa%BO=. |
| oo +osdf*X=*+. |
| o = =+\*O+. |
|o . ooosdo. |
| . . + o3S |
| + . |
| |
| |
| |

It creates C:\Users\user/.ssh/id_ed25519 file and copy the public key into it.

  • Next, Go to Gitlab Dashboard
  • Click on right icon in the header navigation
  • Select Edit Profile
  • Select SSH keys,
  • Open C:\Users\user/.ssh/id_ed25519 and copy the content
  • paste into key text area of below SSH KEYS screen
Gitlab adding ssh keys
  • Click on Add Key button
  • you added the key with to SSH Keys.

Next time, below command to authenticate the user by entering passphrase

B:\work>ssh -T [email protected]
Enter passphrase for key 'C:\Users\Kiran/.ssh/id_ed25519':
Welcome to GitLab, @username!

Now you are free to push the changes