Git 总是询问密码以获取密钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31377629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:11:29  来源:igfitidea点击:

Git always ask passphrase for key

gitgithub

提问by Khanh Pham

I had a problem when using gitat times.

git有时在使用时遇到问题。

When I use the command git pull origin my_branchor git fetchor git push origin my_branch, git always ask passphrase for key. And i didn't understand why ?

当我使用命令git pull origin my_branchor 或git fetchor 时git push origin my_branch,git 总是要求密码短语输入密钥。我不明白为什么?

I hope someone can explain the reason and a way to avoid entering passphrase each time.

我希望有人可以解释原因和避免每次输入密码的方法。

$ git fetch
Enter passphrase for key '/home/khanhpn/.ssh/id_rsa':

回答by Will Vousden

Like Nasreddine says, it's because your key is encrypted with a passphrase to prevent others from reading it.

就像 Nasreddine 所说的那样,这是因为您的密钥是用密码加密的,以防止其他人阅读它。

The most convenient way of using passphrased keys is by using ssh-agentto start an authentication agent (which runs in the background):

使用密码短语最方便的方法是使用ssh-agent启动身份验证代理(在后台运行):

$ eval "$(ssh-agent)"
Agent pid 44304

...and then using ssh-addto register your key with the agent so that it's used automatically for subsequent SSH connections:

...然后用于ssh-add向代理注册您的密钥,以便它自动用于后续的 SSH 连接:

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/khanhpn/.ssh/id_rsa:

You'll be asked to enter your passphrase when you run ssh-add, but you won't need to do so again while ssh-agentis running.

运行时ssh-add,系统会要求您输入密码,但在运行时不需要再次输入ssh-agent

You can find more information on GitHub. Also note that you'll have to do this every time you log in, so you might like to add the eval "$(ssh-agent)"step to your .profilescript.

您可以在 GitHub 上找到更多信息。另请注意,每次登录时都必须执行此操作,因此您可能希望将该eval "$(ssh-agent)"步骤添加到.profile脚本中。

回答by Nasreddine

It's because your private SSH key is protected using a passphrase. You can remove it using this command (not recommended since anyone could copy your key and use it to access your repos/account):

这是因为您的私人 SSH 密钥是使用密码保护的。您可以使用此命令删除它(不推荐,因为任何人都可以复制您的密钥并使用它来访问您的 repos/account):

$ ssh-keygen -p
Enter file in which the key is (/path/to/your/.ssh/key):

enter your current passphrase when prompted here:

在此处提示时输入您当前的密码:

Enter old passphrase:
Key has comment 'rsa w/o comment'

leave empty if you want to remove the passphrase when prompted here:

如果您想在此处提示时删除密码,请留空:

Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.