我在使用git
时遇到了一个问题。
当我使用命令git pull origin my_branch
或者git fetch
或者git push origin my_branch
时,git总是要求我输入密钥密码。我不明白为什么会这样,请问有人能解释一下原因,并告诉我如何避免每次都输入密钥密码吗?
$ git fetch
Enter passphrase for key '/home/khanhpn/.ssh/id_rsa':
我在使用git
时遇到了一个问题。
当我使用命令git pull origin my_branch
或者git fetch
或者git push origin my_branch
时,git总是要求我输入密钥密码。我不明白为什么会这样,请问有人能解释一下原因,并告诉我如何避免每次都输入密钥密码吗?
$ git fetch
Enter passphrase for key '/home/khanhpn/.ssh/id_rsa':
就像 Nasreddine 所说的那样,这是因为您的密钥已经使用密码短语加密,以防止其他人读取它。
使用密码短语密钥的最方便方法是使用 ssh-agent
启动身份验证代理(在后台运行):
$ eval "$(ssh-agent)"
Agent pid 44304
接下来使用ssh-add
将您的密钥注册到代理程序中,以便在之后的SSH连接中自动使用:
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/khanhpn/.ssh/id_rsa:
当您运行 ssh-add
时,会要求您输入密语,但只要 ssh-agent
在运行,就不需要再次输入。
您可以在 GitHub 上找到更多信息,点击这里。另外请注意,每次登录时都必须执行此操作,因此您可能希望将 eval "$(ssh-agent)"
步骤添加到您的 .profile
脚本中。
.profile
里面吗? - Sandesh Sapkota这是因为您的私有SSH密钥受到密码保护。您可以使用此命令将其删除(不建议,因为任何人都可以复制您的密钥并使用它访问您的存储库/帐户):
$ ssh-keygen -p
Enter file in which the key is (/path/to/your/.ssh/key):
在此处提示输入当前的密码短语:
Enter old passphrase:
Key has comment 'rsa w/o comment'
如果您想在此处取消输入密码,请将其留空:
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.