【发布时间】:2021-09-25 00:21:38
【问题描述】:
我正在尝试编写一个 ssh 到远程位置然后执行git pull 的脚本,如下所示
ssh url@location << EOF
--other commands--
git pull
--other commands--
EOF
但是,每当我运行脚本时,它都会失败用户名/密码提示,它永远不会在终端上显示。在这种情况下,我实际上宁愿输入我的凭据而不是对远程机器进行调整,有人知道如何让提示出现吗?
【问题讨论】:
我正在尝试编写一个 ssh 到远程位置然后执行git pull 的脚本,如下所示
ssh url@location << EOF
--other commands--
git pull
--other commands--
EOF
但是,每当我运行脚本时,它都会失败用户名/密码提示,它永远不会在终端上显示。在这种情况下,我实际上宁愿输入我的凭据而不是对远程机器进行调整,有人知道如何让提示出现吗?
【问题讨论】:
你不需要here-doc,你可以write the command as ssh argument:
ssh url@location git pull
这不允许git 询问密码,因为这是仅命令行调用,而git 需要终端来询问密码。所以你必须让ssh 分配一个伪终端:
ssh -t url@location git pull
如果您要运行多个命令 - 将它们全部放在引号中:
ssh url@location "cd /path/to/repo && git pull && echo ok"
ssh -t url@location "cd /path/to/repo && git pull && echo ok"
【讨论】:
您需要使用个人访问令牌在远程计算机上配置您的 git 用户,以免收到用户名/密码提示。
【讨论】: