Getting permission denied (public key) on gitlab

2019-01-21 06:37发布

My problem is that I can't push or fetch from GitLab. However, I can clone (via HTTP or via SSH). I get this error when I try to push :

Permission denied (publickey) fatal : Could not read from remote repository

From all the threads I've looked, here is what I have done :

  • Set up an SSH key on my computer and added the public key to GitLab
  • Done the config --global for username and email
  • Cloned via SSH and via HTTP to check if it would resolve the issue
  • Done the ssh -T git@gitlab.com command

Right now I want to punch my computer. If you have any insight about how to resolve my issue, it would be greatly appreciated.

10条回答
贼婆χ
2楼-- · 2019-01-21 07:00

I solved like this..

Generated a key for Windows using this command:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

but the problem was that after running this command, it popped a line: "Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa): " Here, I was giving only file name because of which my key was getting saved in my pwd and not in the given location. When I did "git clone ", it was assuming the key to be at "/c/Users/xxx/.ssh/id_rsa" location but it was not found, hence it was throwing error.

At the time of key generation 2 files were generated say "file1" & "file1.pub". I renamed both these files as

file1 -> id_rsa 

and

file1.pub -> id_rsa.pub

and placed both in the location "/c/Users/xxx/.ssh/"

查看更多
闹够了就滚
3楼-- · 2019-01-21 07:05

In my case, it wasn't a gitlab problem, but a sshd configuration one. The ssh server didn't allow connection except for a list of users. The user git, the one connecting remotely to gitlab, wasn't in that list. So, check this before anything else.

You can check your ssh server configuration in /etc/ssh/sshd_config. If you have a line with the option AllowUsers, add git to it:

AllowUsers user1 user2 user3 git
查看更多
狗以群分
4楼-- · 2019-01-21 07:06

Step 1: Added a config file in ~/.ssh/ folder 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.

查看更多
Animai°情兽
5楼-- · 2019-01-21 07:07

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.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-21 07:08

Go to the terminal and regenerate the ssh key again. Type ssh-keygen. It will ask you where you want to save it, type the path.

Then copy the public key to gitlabs platform. It usually starts with ssh-rsa.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-21 07:11

I have gitlab running with docker, this is what I did to fix my problem.

Found that inside docker /var/log/gitlab/sshd/current there were multiple occurences of a message:

Authentication refused: bad ownership or modes for file /var/opt/gitlab/.ssh/authorized_keys

After which I changed ownership of that file from 99:users to git:users with:

chown git:users authorized_keys

查看更多
登录 后发表回答