2017-03-16 25 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