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

How do I pull from a git repo on a remote machine through ssh?

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

我正在尝试 运行 完成 git 拉取的 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 连接到远程机器时。导航到目录并 运行ning a git pull.

没问题

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

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

令人沮丧的是,我能够通过 ssh 连接到远程计算机并且 运行 拉动很好,但不能 运行 使用上述格式的命令。

非常感谢您的帮助!

根据我对您的问题的了解,这是我的建议: [虽然信息有些不完整]

GIT 在 root 用户目录中读取你的 id_rsa.pub : /home/root/.ssh/id_rsa.pub

这就是为什么 /home/your_username/.ssh/id_rsa.pub 中的密钥可能无法被 git 读取的原因。

因此,请检查并在 /home/root/.ssh/

中创建密钥
$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ cat id_rsa.pub

希望对您有所帮助。

使用 -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.