问题描述
我生成了一个 ssh 密钥并将其设置在 bitbucket 上,一切都很好,但是当我重新启动计算机时,密钥现在被拒绝了。我重新制作了它,当我使用新的终端窗口时它再次失败。如果有帮助,我在 Windows 上。
解决方法
这通常取决于您使用的操作系统,可能有多种原因。
- 您的 shell/终端不会在启动时初始化 SSH 代理
- 您的操作系统/终端不会在午餐时加载默认私钥
- 如果您重命名私钥,它也将不再知道如何加载它。
最简单的解决方法是将以下几行添加到您的 ~/.profile
、~/.bash_profile
或 ~/.zshrc
。
eval $(ssh-agent) # create a agent for the shell
ssh-add ~/.ssh/id_rsa # this is one of the default file names,changes as required
Windows 也支持 Git Bash 的类似方式。
这应该会在每次午餐或标签时将您的密钥加载到 shell。
Ps:如果你的私钥有密码,每次运行都会提示你输入密码。
这是启动 Git Bash 时的样子
Agent pid 16516
Identity added: /c/Users/Praveen/.ssh/id_rsa (/c/Users/Praveen/.ssh/id_rsa)
Praveen@DESKTOP MINGW64 ~/Desktop
$