linux - 如何通过 ssh 从远程计算机上的 git 存储库中提取数据?

标签 linux git ssh gitlab

在我完成测试并准备更新生产(python Flask 应用程序和支持类)后,我有几台远程机器需要从存储库中提取数据。几台机器也需要从不同的分支中 pull 出。我一直在通过 SSH 连接到每台机器以运行 git pull,但这越来越烦人且耗时。

我正在尝试运行一个完成 git pull 的 ssh 命令。这是我试过的:

ssh dev@<remote IP> "cd /home/dev/<repo> && git pull"

我得到了一个

Permission denied (publickey). fatal: Could not read from remote repository.

我能够很好地运行其他不与远程源交互的 git 命令。如:

ssh dev@<remote IP> "cd /home/dev/<repo> && git remote -v"

当我真正通过 ssh 连接到远程机器时。导航到目录并运行 git pull 没有问题。

我还确保将 ssh key 添加到 ssh-agent,这样 key 上的密码提示就不会成为问题。

我认为这可能是一个 key 权限问题,所以我仔细检查了我运行命令的用户是否可以读取该 key 。

令人沮丧的是,我能够通过 ssh 连接到远程机器并正常运行 pull ,但无法运行上述格式的命令。

非常感谢您的帮助!

最佳答案

使用 -A选项。

ssh -A dev@<remote IP> "cd /home/dev/<repo> && git pull"

当我试图找到这个问题的答案时,我在这里的评论中遇到了这个选项:https://serverfault.com/questions/762983/ssh-and-git-pull-from-remote-server

来自 https://linux.die.net/man/1/ssh :

If the ForwardAgent variable is set to ''yes'' (or see the description of the -A and -a options above) and the user is using an authentication agent, the connection to the agent is automatically forwarded to the remote side.

关于linux - 如何通过 ssh 从远程计算机上的 git 存储库中提取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38816663/

相关文章:

mongodb - 如何在服务器上执行 mongodump 并使用 golang 将其传输到本地计算机?

ssh - 如何使用 Ansible 设置 SSH 连接?

linux - 向 255.255.255.255 广播 UDP 数据包

c - 使用系统调用在 Linux 中使用 C 将两个文本文件合并为新文件(每一行来回)

php - Application.cpp :422: Mismatch between target UID (584) and UID (99) of file 中的 SoftException

git - 为什么 "git log -‌- foo"对删除的文件 foo 不起作用?

linux - 如何创建 Nagios 监视器

git - 将 git pull 从新 git 存储库上的远程分支撤消到 git pull 之前的状态

git - 如何在所有 git 消息提交中更改特定字符串?

python - Paramiko Python : IOError: [Errno 13] Permission denied