在我完成测试并准备更新生产(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/