【问题标题】:git pull while ssh into remote shows no prompts for username/password当 ssh 进入远程时 git pull 不提示输入用户名/密码
【发布时间】:2021-09-25 00:21:38
【问题描述】:

我正在尝试编写一个 ssh 到远程位置然后执行git pull 的脚本,如下所示

ssh url@location << EOF
--other commands--
git pull
--other commands--
EOF

但是,每当我运行脚本时,它都会失败用户名/密码提示,它永远不会在终端上显示。在这种情况下,我实际上宁愿输入我的凭据而不是对远程机器进行调整,有人知道如何让提示出现吗?

【问题讨论】:

    标签: bash git ssh


    【解决方案1】:

    你不需要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"
    

    【讨论】:

    • 我在这里使用标准输入文档,因为我需要执行其他命令,例如 cd'ing 到存储库。我可以将此添加到问题中
    • @wjmccann 我更新了多个命令的答案。
    【解决方案2】:

    您需要使用个人访问令牌在远程计算机上配置您的 git 用户,以免收到用户名/密码提示。

    【讨论】:

    • 在问题正文中我声明我不想配置以便不会出现提示,我只想让它出现在我的终端中
    猜你喜欢
    • 2018-07-18
    • 2016-01-30
    • 1970-01-01
    • 2011-11-26
    • 2017-07-26
    • 2016-04-08
    • 2014-02-28
    • 2012-11-08
    • 2013-09-01
    相关资源
    最近更新 更多