2011-04-08 37 views
1

我建立了一個PHP腳本,執行對特定文件夾的混帳獲取:的Git從PHP文件中使用了shell_exec私鑰取

確切的命令是:

usr/bin/git --git-dir=/home/bathan/www/sync_test/repo3//.git --work-tree=/home/bathan/www/sync_test/repo3/ fetch 

當然,如果我在命令行上運行它可以很好地工作。

現在,當我運行這個使用了shell_exec我得到以下錯誤:

Permission denied, please try again. 
Permission denied, please try again. 
Permission denied (publickey,gssapi-with-mic,password). 
fatal: The remote end hung up unexpectedly 

展望服務器的嘗試連接,確切的錯誤是:

Apr 8 10:52:17 myserver sshd[26230]: Failed password for git from 192.15.136.253 port 32878 ssh2

那麼,好吧。我猜這個shell_exec不能讀取我設置的〜/ .ssh/id_rsa密鑰。所以我給這個文件777權限,我得到這個錯誤。

@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@ Permissions 0777 for '/home/bathan/.ssh/id_rsa' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. bad permissions: ignore key: /home/bathan/.ssh/id_rsa Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-with-mic,password). fatal: The remote end hung up unexpectedly

所以我想git是能夠讀取密鑰文件。如果我把它恢復到正確的權限,我會再次回到第一個錯誤。

注意:我的apache服務器設置爲與我的同一用戶(bathan)一起運行,並且這是一個ubuntu盒子。

這是SSH -v響應

OpenSSH_5.5p1 Debian-4ubuntu5, OpenSSL 0.9.8o 01 Jun 2010 
Pseudo-terminal will not be allocated because stdin is not a terminal. 
debug1: Reading configuration data /home/bathan/.ssh/config 
debug1: Applying options for gitserver 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: Applying options for * 
debug1: Connecting to git.myserver.com [77.171.171.229] port 22. 
debug1: Connection established. 
debug1: identity file /home/bathan/.ssh/id_rsa type 1 
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-1023 
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-1023 
debug1: identity file /home/bathan/.ssh/id_rsa-cert type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3 
debug1: match: OpenSSH_4.3 pat OpenSSH_4* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_5.5p1 Debian-4ubuntu5 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP 
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY 
debug1: Host 'git.myserver.com' is known and matches the RSA host key. 
debug1: Found key in /home/bathan/.ssh/known_hosts:4 
debug1: ssh_rsa_verify: signature correct 
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,gssapi-with-mic,password 
debug1: Next authentication method: gssapi-with-mic 
debug1: Unspecified GSS failure. Minor code may provide more information 
Credentials cache file '/tmp/krb5cc_1000' not found 
.. 
.. 

什麼想法?

回答

2

確定的PHP腳本使用相同的用戶在安裝~/.ssh/id_rsa與執行?

E.g.在許多環境中,網絡服務器(例如Apache)由www-data運行。而我只是猜測www-data不是id_rsa所在的$HOME/.ssh/的用戶。

嘗試硬編碼的SSH密鑰的位置在.ssh/config

Host gitserver 
Hostname fqdn.example.org 
IdentityFile /home/THE-USER/.ssh/id_rsa 

如果這沒有幫助,調試像這樣:

從PHP:

<?php 
shell_exec("ssh -v gitserver"); 

查看在這種情況下使用哪些鍵來了解爲什麼它可能不起作用。

+0

正如我所說,我的apache服務器設置爲與我的同一用戶(bathan)一起運行。我在apache.conf上修改了這個目的,以確保使用完全相同的用戶。 – Bathan 2011-04-08 18:44:33

+0

好的,擴展我的答案,用一個有用的調試 – Till 2011-04-08 18:57:43

+0

而不是改變Apache作爲你的用戶運行,爲什麼不把你的密鑰複製到Apache的.ssh目錄? – 2011-04-08 19:05:08

0

我發現了這個問題。

rsa_id正在使用釋義,顯然沒有被腳本輸入。

我刪除與意譯:SSH-凱基-p和它的工作就像一個魅力。

感謝大家的幫助!