2017-03-16 48 views
0

我已将克隆到本地文件夹(位于Windows 7 PC上)我的网站(托管在CentOS 7服务器上)的git存储库中。我想要使​​用git命令,如git pull,而不必每次输入用户的密码。Git调用SSH与不工作的密钥

>git remote -v 
origin ssh://[email protected]:1234/home/mylinuxuser/domains/mydomain/public_html/ (fetch) 
origin ssh://[email protected]:1234/home/mylinuxuser/domains/mydomain/public_html/ (push) 

我已经创建了一个密钥对。该id_rsa文件是C:\Users\mywindowsuser\.sshid_rsa.pub我已经发送到服务器,并添加到authorized_keys文件:

cat id_rsa.pub >> authorized_keys 

authorized_keys文件由mylinuxuser拥有和访问权限是600.ssh文件夹的访问权限为700

在我的本地机器上,我曾与

Host * 
    IdentityFile ~/.ssh/id_rsa 

我试图在Linux服务器上重新启动SSH service sshd restart作为su以及充满config文件中.ssh文件夹中。没有帮助。

还增加id_rsa到许多路径,因为Ifound一些答案领先的堆栈是这样的:这些工作

C:\Program Files\Git\.ssh 
C:\Program Files (x86)\Git\.ssh 
C:\Users\mywindowsuser\AppData\Local\VirtualStore\Program Files\Git\.ssh 
C:\Users\mywindowsuser\AppData\Local\VirtualStore\Program Files (x86)\Git\.ssh 

无。我想知道是否有其他文件存在干扰。例如,我在C:\Users\mywindowsuser\.ssh中有environment文件和known_hosts文件,但我怀疑它。

不过,任何时候我尝试打电话git pull它要求mylinuxuser密码...

任何帮助,将不胜感激!

[编辑]在评论中建议的结果:

ssh -v -p1234 [email protected] 
OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015 
debug1: Reading configuration data /c/Users/mywindowsuser/.ssh/config 
debug1: /c/Users/mywindowsuser/.ssh/config line 1: Applying options for * 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: Connecting to 1.2.3.4 [1.2.3.4] port 1234. 
debug1: Connection established. 
debug1: identity file /c/Users/mywindowsuser/.ssh/id_rsa type 1 
debug1: key_load_public: No such file or directory 
debug1: identity file /c/Users/mywindowsuser/.ssh/id_rsa-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_7.1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 
debug1: Authenticating to 1.2.3.4:1234 as 'mylinuxuser' 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr [email protected] none 
debug1: kex: client->server aes128-ctr [email protected] none 
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent 
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP 
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY 
debug1: Server host key: ssh-rsa SHA256:verylongkey 
debug1: Host '[1.2.3.4]:1234' is known and matches the RSA host key. 
debug1: Found key in /c/Users/mywindowsuser/.ssh/known_hosts:1 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: Roaming not allowed by server 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: publickey 
debug1: Offering RSA public key: /c/Users/mywindowsuser/.ssh/id_rsa 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: password 
+0

我假设你向git-hub帐户添加了公共ssh密钥,但你可能需要将你的新私钥添加到ssh-agent。试试'ssh-add〜/ .ssh/id_rsa'。确保'ssh-agent'正在运行。 – jiveturkey

+0

这不是一个github帐户,因为我说它是一个私人服务器。我做了你的建议 - 在普通的cmd中,它没有工作,但它在git bash中做了,并且我添加了标识:/c/Users/mywindowsuser/.ssh/id_rsa(/c/Users/mywindowsuser/.ssh/id_rsa )'作为答案...但是,当我尝试'git pull'时它仍然要求输入密码,所以它不起作用,很遗憾 –

+1

尝试通过ssh以详细的方式登录进行调试。 'ssh -v -v -p 1234 mylinuxuser @ 1.2.3.4' – Schwern

回答

0

我知道问题是什么你面对的问题。

您需要提供访问权限。

尝试chmod 600,它会解决你的问题。

chmod 700/root/.ssh/authorized_keys 
chmod 600 /root/.ssh/authorized_keys 
restorecon -R -v /root/.ssh 

上面的东西解决了你的问题,那么你不需要关注这个。 确保其他用户无法修改您的目录。

chmod g-w,o-w /home/USERNAME 
+0

没有工作,但无论如何感谢 –

+1

这里的含义是你允许远程登录作为根。不要鼓励人们以根的身份登录,就像走动一下拿着一把装满枪的枪,安全关闭,手指放在扳机上。让他们使用sudo。 – Schwern

+1

@Schwern,你说的对,以root身份登录是不鼓励的。 – LethalProgrammer