Getting permission denied (public key) on gitlab
There is a very simple solution to this: instead of working with ssh - move to https. to do this: in your project folder you have a .git folder in there - you have a config file - open it in a text editor and change the line
url [email protected]:yourname/yourproject.git
to
url = https://gitlab.com/yourname/yourproject.git
I found this after searching a lot. It will work perfectly fine for me.
- Go to "Git Bash" just like cmd. Right click and "Run as Administrator".
- Type
ssh-keygen
- Press enter.
- It will ask you to save the key to the specific directory.
- Press enter. It will prompt you to type password or enter without password.
- The public key will be created to the specific directory.
- Now go to the directory and open
.ssh
folder. - You'll see a file
id_rsa.pub
. Open it on notepad. Copy all text from it. - Go to https://gitlab.com/-/profile/keys or
- Paste here in the "key" textfield.
- Now click on the "Title" below. It will automatically get filled.
- Then click "Add key".
Now give it a shot and it will work for sure.
Step 1:
Added a config file in ~/.ssh/config
file which looks like
User git
Hostname gitlab.com
IdentityFile ~/.ssh/id_rsa_gitlab
TCPKeepAlive yes
IdentitiesOnly yes
Step 2: Just clone the git repo WITHOUT sudo.
Documentation: https://gitlab.com/help/ssh/README#working-with-non-default-ssh-key-pair-paths
** sometimes you have the config in your ~/.ssh/config
, but, IdentityFile path is not correct. you can check the file name like this ls ~/.ssh/
. the file is normally is id_ed25519
for gitlab. thus the correct config is IdentityFile ~/.ssh/id_ed25519
I think the simple solution is to add private key to authentication agent (if your key is not ~/.ssh/id_rsa
),
ssh-add ~/.ssh/<your private key>
You basically let the ssh-agent
take care of it.
Additionally, you can add it permanently.