[英]Git always asks for my ssh-key passphrase
我在使用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
腳本中。
這是因為您的私人 SSH 密鑰是使用密碼保護的。 您可以使用此命令刪除它(不推薦,因為任何人都可以復制您的密鑰並使用它來訪問您的 repos/account ):
$ 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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.