我们的symfony项目除了使用公共源之外,还在我们自己的gitlab服务器上使用了一个私有存储库,可以通过ssh访问。
如果我只将这个私有存储库克隆到我的本地ubuntu机器上,一切都很好。如果我使用
$ sudo composer install
在包括这个存储库的项目中,我得到了以下错误消息:
[RuntimeException]
Failed to execute git clone --mirror 'git@gitlab.con.example.com:myprivaterepo.git' '/home/aliebermann/.composer/cache/vcs/git-gitlab.con.example.com-myprivaterepo.git/'
Cloning into bare repository '/home/myuser/.composer/cache/vcs/git-gitlab.con.example.com-myprivaterepo.git'...
__________________________________________________________________
| |
| This system is for the use of authorized users only. Usage of |
| this system may be monitored and recorded by system personnel. |
| |
| Anyone using this system expressly consents to such monitoring |
| and is advised that if such monitoring reveals possible |
| evidence of criminal activity, system personnel may provide the |
| evidence from such monitoring to law enforcement officials. |
|__________________________________________________________________|
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我想这是因为我的ssh密钥位于我的私人住宅中,如果我以sudo的身份运行,它们就不会被调用。由于你不能像在其他Linux系统上那样简单地使用"su",我不知道如何解决这个问题。
不过,让作曲家在没有须藤的情况下运行是行不通的。
接下来,我将所有ssh密钥复制到/root/.ssh,但由于它们是受密码保护的,我遇到了下一个问题:
$ sudo ssh-add -k
[sudo] Password for myuser:
Could not open a connection to your authentication agent.
为root
创建ssh密钥并授权其访问。
你并不真的需要su
来做这件事。但如果你真的很想,你可以用成为root
sudo su -
更新
所以我看到您将用户密钥复制到了root
。到目前为止还不错。
$ sudo ssh-add -k [sudo] Password for myuser: Could not open a connection to your authentication agent.
似乎没有为root
运行身份验证代理。你需要先开始一个。这里有一种方法:
# become root; will ask for user's password
sudo su -
# start ssh-agent
eval $(ssh-agent)
# add private key to agent; will ask for passphrase
ssh-add
之后,您可以使用root
执行composer install
。
您也可以添加
Defaults env_keep+=SSH_AUTH_SOCK
连接到服务器的sudoers文件,并在连接到服务器时将-A添加到ssh命令行。假设您在ssh代理中有来自与存储库相关联的本地机器的正确密钥,
sudo composer install
应该只是工作。