【问题标题】:Why can't I `source` ssh-agent and ssh-add with in bash script?为什么我不能在 bash 脚本中使用 `source` ssh-agent 和 ssh-add?
【发布时间】:2021-10-27 02:55:18
【问题描述】:

当我尝试git push 时,我收到以下错误。

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我知道我应该在这里指定我自己的密钥,所以我在 bash 窗口中键入以下内容,它工作正常。

ssh-agent bash
ssh-add ~/.ssh/id_rsa_lrz
git push

但是,我想让事情变得简单,所以我有一个这样的 set_env.sh

ssh-agent bash
ssh-add ~/.ssh/id_rsa_lrz

然后我像这样在我的 bash 窗口中输入

. set_env.sh
git push

但是,我再次收到 ERROR: Repository not found. 错误,但为什么?

【问题讨论】:

    标签: bash ssh ssh-agent


    【解决方案1】:

    这是因为当你运行时:

    . set_env.sh
    

    您将在 ssh-agent bash 设置的 bash 会话中,其中 ssh-add ~/.ssh/id_rsa_lrz 尚未运行。

    你需要的是放入 set_env.sh

    eval "$(/usr/bin/ssh-agent)"
    ssh-add ~/.ssh/id_rsa_lrz
    

    【讨论】:

      猜你喜欢
      • 2022-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多