1

特定のフォルダーで git fetch を実行する php スクリプトを作成しました。

正確なコマンドは次のとおりです。

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

接続しようとしているサーバーを調べると、正確なエラーは次のとおりです。

4 月 8 日 10:52:17 myserver sshd[26230]: 192.15.136.253 ポート 32878 ssh2 からの git のパスワードの失敗

じゃあ良いよ。この shell_exec は、設定した ~/.ssh/id_rsa キーを読み取ることができないと思います。したがって、そのファイルに 777 のアクセス許可を与えると、このエラーが発生します。

@@@@@ @ 警告: 保護されていない秘密鍵ファイル! @ @@@ '/home/bathan/.ssh/id_rsa' のパーミッション 0777 が開きすぎています。秘密鍵ファイルは、他のユーザーがアクセスできないようにすることをお勧めします。この秘密鍵は無視されます。不正な権限: キーを無視: /home/bathan/.ssh/id_rsa 権限が拒否されました。もう一度お試しください。許可が拒否されました。もう一度お試しください。許可が拒否されました (公開鍵、gssapi-with-mic、パスワード)。致命的: リモート エンドが予期せず電話を切りました

したがって、git IS はキー ファイルを読み取ることができると思います。正しい権限に戻すと、最初のエラーに戻ります。

注: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
..
..

何か案は?

4

2 に答える 2

2

セットアップに使用したのと同じユーザーで PHP スクリプトが実行されています~/.ssh/id_rsaか?

たとえば、多くの環境では、Web サーバー (Apache など) は によって実行されwww-dataます。そして、それは が配置www-dataされているユーザーではないと推測しているだけです。$HOME/.ssh/id_rsa

あなたの ssh-key の場所をハードコーディングしてみてください.ssh/config:

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

これで問題が解決しない場合は、次のようにデバッグします。

PHP から:

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

この場合にどのキーが使用されているかを確認して、機能しない理由を理解してください。

于 2011-04-08T18:41:35.183 に答える
0

問題が見つかりました。

rsa_id はパラフレーズを使用しており、明らかにスクリプトによって入力されていませんでした。

: ssh-keygen -p で言い換えを削除したところ、魅力的に機能しました。

みんなの助けに感謝します!!

于 2011-04-08T19:50:39.500 に答える