【问题标题】:Git always asks for my ssh-key passphraseGit 总是询问我的 ssh-key 密码
【发布时间】:2015-10-01 09:05:16
【问题描述】:

我在使用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 github


【解决方案1】:

就像 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 时您无需再次输入密码。

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

【讨论】:

  • 是一个文件.profile,我们需要将该命令放入该文件中吗?
【解决方案2】:

这是因为您的 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.

【讨论】:

  • 这很好用,但您必须了解任何有权访问您的私钥文件的人都可以在没有任何密码的情况下访问您的远程帐户(例如,如果您的笔记本电脑被盗怎么办?)。正如 Will Vousden 所建议的,一个更安全的选择是使用 ssh-agent。
  • 也许我应该强调那部分
猜你喜欢
  • 2012-04-19
  • 2015-08-10
  • 2014-07-21
  • 2021-03-29
  • 1970-01-01
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 2012-11-30
相关资源
最近更新 更多