可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
I found this after searching alot. 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 .
- 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.
回答2:
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.
回答3:
make sure you are not running sudo git clone git@gitlab.com:project/somethiing.git
, otherwise ssh will look in /root/.ssh
instead of the key you uploaded ~/.ssh/id_rsa
回答4:
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.
回答5:
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
回答6:
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
回答7:
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.
回答8:
if you are in linux or macox , just try this in terminal:
if it return nothing, try this:
it must create identity in ~/.ssh/id_rsa
after retry :
it must return your identity, so after retry to clone , it's must work
NB: don't forget to add your ssh key in your profile gitlab
thanks
回答9:
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/"
回答10:
I added my ~/.ssh/id_rsa.pub
to the list of known SSH Keys in my GitLab settings https://gitlab.com/profile/keys. That solved the problem for me. :-)