所以我想让git在我的新服务器(4.5.6.7 / 10.0.0.111)上使用我的repo服务器(1.2.3.4)(debian)。
我的回购的.git /configuration
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [branch "master"] remote = origin merge = refs/heads/master [remote "origin"] url = [email protected]:/opt/git/repo.git fetch = +refs/heads/*:refs/remotes/origin/*
我得到这个错误:
[ec2-user@ip-10-0-0-111 html]$ sudo git pull Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
我的公钥存在于/home/git/.ssh/authorized_keys
我以前我被提示为我的回购服务器上的用户(不是我的密钥文件密码)的用户密码的密码。 然后,我禁用了git用户的密码authentication,并收到拒绝的权限。 在这段时间,现在与上面的错误我能够通过SSH成功login :
ssh [email protected]
没有密码提示或这样的:
debug1: Offering RSA public key: /home/ec2-user/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 279 debug1: Authentication succeeded (publickey).
在repo服务器(1.2.3.4)上成功的sshlogin如下所示:/var/log/auth.log:
Feb 22 15:45:44 hostname sshd[20142]: Connection from 4.5.6.7 port 50409 Feb 22 15:45:44 hostname sshd[20142]: Found matching RSA key: <fingerprint> Feb 22 15:45:44 hostname sshd[20142]: Accepted publickey for git from 4.5.6.7 port 50409 ssh2 Feb 22 15:45:44 hostname sshd[20142]: pam_unix(sshd:session): session opened for user git by (uid=0)
当我尝试git拉这是什么auth.log看起来像:
Feb 22 15:46:41 hostname sshd[20177]: Connection from 4.5.6.7 port 50410
然后没有更多。
当正常的ssh命令完美工作时,如何debugginggit的git ssh身份validation失败?
你做sudo下的git pull ,这是问题。 只做
git pull
会为你工作。 也在做
sudo ssh [email protected]
会失败的。 问题是, sudo改变用户,它不再看到你的身份文件/home/ec2-user/.ssh/id_rsa (它在/root/.ssh/id_rsasearch)。 用普通用户进行pull操作,或者将密钥复制/移动到目标用户的适当位置( root )。
你的SSH密钥不是无效的。
ssh-keygen -t rsa -C "[email protected]"会为当前用户生成ssh密钥。 例如:
$ whoami nodejh # It will generate the ssh key for user: nodejh $ ssh-keygen -t rsa -C "[email protected] # Check that you are connecting to the correct server $ ssh -T [email protected] Hi username! You've successfully authenticated...
sudo ssh-keygen -t rsa -C "[email protected]会为root生成ssh密钥,这样ssh -T [email protected]将会返回Permission Denied (publickey) ,但是sudo ssh -T [email protected]工作正常。
如果要为用户生成ssh密钥: admin ,则可以将当前用户更改为admin然后生成ssh密钥。
# change the current user to admin $ su admin # generate ssh key for `admin` $ ssh-keygen -t rsa -C "[email protected]`