sudo -u gitクローン

sudo -u gitクローン

Ubuntu Server 14.04を使用しています。

私は次のように動作するApache Webサーバーを使用しています。www-データ。私はそれをしなければならないgit clone スクリプトから(ウェブフック)。スクリプトが実行されますwww-データユーザーの権利。

git clone権限の問題があるディレクトリで通常のユーザーとして実行しても/var/www/htmlかまいません。なぜなら私が欲しいからです。www-データユーザーはそこに書くことができます。

これwww-データユーザーの家はに設定され、/var/wwwSSHキーはにあります/var/www/.ssh

私が実行した場合:

sudo git clone [email protected]:user/repo.git

期待どおりに動作します。私のユーザーのSSH公開鍵はauthorized_keys@my.git.serverにリストされています。

ただし、bashスクリプトで実行する必要があり、一般権限が必要です。

だから公開SSHキーをコピーしました。www-データユーザーは my.git.server の authorized_keys ファイルにアクセスします。理論的には、これは次のことを意味するはずです。www-データユーザーはSSH経由でgit cloneを起動できますが、これはパスワードを必要とせず、非常に安全です。

だからそれをテストするには、次のようなものを実行する必要があるようです。

sudo -u www-data -H git clone [email protected]:user/repo.git

私の理解は、これが私が仮定させることですwww-データ~/.sshユーザーがSSH経由で実行しているときに作業ディレクトリになるように自分のホームディレクトリを設定します。git clone

コマンドを実行しようとしたときに発生する問題は、次のエラー出力です。

Cloning into 'repo'...
fatal: 'user/repo.git' does not appear to be a git repository
fatal: Could not read from remote repository.

私が言ったように、sudoで実行しても問題ありません。 www-dataで実行しようとしたときだけ。コマンドの解釈方法に問題があるため、パス/ストア名を誤って読み取るように見えますか?


l0b0の応答によると、出力は次のようになります。

james-c@WebHost-1:~$ sudo ssh -v [email protected] 2>&1 | grep 'identity file'
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
james-c@WebHost-1:~$ sudo -u www-data ssh -v [email protected] 2>&1 | grep 'identity file'
debug1: identity file /var/www/.ssh/id_rsa type 1
debug1: identity file /var/www/.ssh/id_rsa-cert type -1
debug1: identity file /var/www/.ssh/id_dsa type -1
debug1: identity file /var/www/.ssh/id_dsa-cert type -1
debug1: identity file /var/www/.ssh/id_ecdsa type -1
debug1: identity file /var/www/.ssh/id_ecdsa-cert type -1
debug1: identity file /var/www/.ssh/id_ed25519 type -1
debug1: identity file /var/www/.ssh/id_ed25519-cert type -1

私がここで何を探しているのかわかりませんか?

ベストアンサー1

私も同じ問題がありましたが、このようにユーザーを切り替えると環境が保存されているようです。これは無効なGit設定をロードし、権限の問題によって失敗します。

私の場合は、次のコマンドを使用して問題をバイパスしました。

sudo -u deploydeputy /bin/bash -c "export HOME=/home/deploydeputy && git clone [email protected]:inventid/cdn.git /tmp/cdn"

おすすめ記事