Git不断询问我ssh密钥密码

本文翻译自:Git keeps asking me for my ssh key passphrase

I created keys as instructed in the github tutorial, registered them with github, and tried using ssh-agent explicitly — yet git continues to ask me for my passphrase every time I try to do a pull or a push. 我按照github教程中的说明创建了密钥,并在github上注册了它们,然后显式尝试使用ssh-agent-但是git每次尝试进行拉式或推式操作时,都会继续询问我密码。

What could be the cause? 可能是什么原因?


#1楼

参考:https://stackoom.com/question/g5tt/Git不断询问我ssh密钥密码


#2楼

It sounds like you may be having trouble with SSH-Agent itself. 听起来您可能无法使用SSH-Agent本身。 I would try troubleshooting that. 我会尝试排除故障。

1) Did you do ssh-add to add your key to SSH? 1)您是否通过ssh-add将密钥添加到SSH?

2) Are you closing the terminal window between uses, because if you close the window you will have to enter the password again when you reopen it. 2)您是否在两次使用之间关闭了终端窗口,因为如果您关闭终端窗口,则在重新打开它时必须再次输入密码。


#3楼

Once you have started the SSH agent with: 使用以下命令启动SSH代理后:

eval $(ssh-agent)
  1. You have to add your private key to it: 您必须在其中添加私钥:

     ssh-add 

    This will ask you your passphrase just once, and then you should be allowed to push, provided that you uploaded the public key to Github. 这将只询问您一次密码,如果您将公钥上传到Github,则应该允许您输入密码。

  2. To save key permanently on macOS: 要在macOS上永久保存密钥:

     ssh-add -K 

    This will persist it after you close and re-open it by storing it in user's keychain. 关闭并通过将其存储在用户的钥匙串中重新打开后,它将保留它。


#4楼

I had a similar issue, but the other answers didn't fix my problem. 我遇到了类似的问题,但是其他答案并没有解决我的问题。 I thought I'd go ahead and post this just in case someone else has a screwy setup like me. 我以为我会继续发布此消息,以防其他人像我一样搞怪设置。

It turns out I had multiple keys and Git was using the wrong one first. 原来我有多个键,而Git首先使用的是错误的键。 It would prompt me for my passphrase, and I would enter it, then Git would use a different key that would work (that I didn't need to enter the passphrase on). 它会提示我输入密码,然后输入密码,然后Git将使用一个可以使用的其他密钥(不需要输入密码)。

I just deleted the key that it was using to prompt me for a passphrase and now it works! 我只是删除了用来提示我输入密码的密钥,现在它可以了!


#5楼

I would try the following: 我会尝试以下方法:

  1. Start GitBash 启动GitBash
  2. Edit your ~/.bashrc file 编辑~/.bashrc文件
  3. Add the following lines to the file 将以下行添加到文件

SSH_ENV=$HOME/.ssh/environment

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

if [ -f "${SSH_ENV}" ]; then
     . ${SSH_ENV} > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi
  1. Save and close the file 保存并关闭文件
  2. Close GitBash 关闭GitBash
  3. Reopen GitBash 重新打开GitBash
  4. Enter your passphrase 输入您的密码

#6楼

What worked for me on Windows was (I had cloned code from a repo 1st): 在Windows上对我有用的是(我从仓库1st克隆了代码):

eval $(ssh-agent)
ssh-add 
git pull 

at which time it asked me one last time for my passphrase 当时它最后一次要求我输入密码

Credits: the solution was taken from https://unix.stackexchange.com/questions/12195/how-to-avoid-being-asked-passphrase-each-time-i-push-to-bitbucket 鸣谢:解决方案取自https://unix.stackexchange.com/questions/12195/how-to-a-avoid-being-asked-passphrase-each-time-i-push-to-bitbucket

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值