Git SSH 访问设置问题

标签 git bash ssh

我目前正在使用 Cywin,并且之前已经进行过设置。重新安装并重新进行设置后,它不再工作。

我按照此处的说明进行操作

https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

我使用以下代码修改了 .bashrc

SSH_ENV="$HOME/.ssh/environment"

# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
    echo succeeded
    chmod 600 "$SSH_ENV"
    . "$SSH_ENV" > /dev/null
    ssh-add
}

# test for identities
function test_identities {
    # test whether standard identities have been added to the agent already
    ssh-add -l | grep "The agent has no identities" > /dev/null
    if [ $? -eq 0 ]; then
        ssh-add
        # $SSH_AUTH_SOCK broken so we start a new proper agent
        if [ $? -eq 2 ];then
            start_agent
        fi
    fi
}

# check for running ssh-agent with proper $SSH_AGENT_PID
if [ -n "$SSH_AGENT_PID" ]; then
    ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
    if [ $? -eq 0 ]; then
    test_identities
    fi
# if $SSH_AGENT_PID is not properly set, we might be able to load one from
# $SSH_ENV
else
    if [ -f "$SSH_ENV" ]; then
    . "$SSH_ENV" > /dev/null
    fi
    ps -ef | grep "$SSH_AGENT_PID" | grep -v grep | grep ssh-agent > /dev/null
    if [ $? -eq 0 ]; then
        test_identities
    else
        start_agent
    fi
fi

我在 ~/.ssh/config 中的配置文件如下

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa

以前这按预期工作。当我启动 Cygwin 时,系统会提示我输入密码,然后在执行 ssh-add -l 时,我会显示我添加的身份。

但是,现在它出现并说

正在初始化新的 SSH 代理...

成功

然后它就会带我进入提示符。

执行 ssh-add -l 时,它不显示任何身份。

我想知道 bash 代码中是否存在可能导致此问题的错误。

最佳答案

由于您没有表明系统会提示您输入密码,因此您的 ssh key 有问题。如果我将 ~/.ssh/id_rsa 移动到另一个文件,我会得到同样的结果。

您可能必须重新生成 ssh key 。

关于Git SSH 访问设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16883872/

相关文章:

git - Apache 和 GitLab 在同一台服务器上

git - 在预提交 Hook 中引发 git 警告

Git 远程日志和变更请求

Bash while 循环仅在 body 包含 ssh 时迭代一次

mysql - 附加 MySQL 访问主机 Cpanel 的保存位置

python - 通过多个主机的pexpect ssh

windows - 来自 Win10 和 Ubuntu WSL 的 Git 提交 - 如何处理文件执行模式更改?

bash - 如何增加属性文件中的数值

linux - 检查新上传的文件并在 bash 脚本中重定向其他文件中的文件数据?

r - Bash/Linux 在 .txt 文件中查找非 ASCII 字符并将其替换为 ASCII 字符