【发布时间】:2026-02-06 05:10:01
【问题描述】:
我忘记了我在 Git 中的密码。我该如何重置它?我在 Stack Overflow 上找到了两个解决方案,但我想知道要遵循什么流程来重置或获取它。
【问题讨论】:
标签: git github ssh ssh-keys passphrase
我忘记了我在 Git 中的密码。我该如何重置它?我在 Stack Overflow 上找到了两个解决方案,但我想知道要遵循什么流程来重置或获取它。
【问题讨论】:
标签: git github ssh ssh-keys passphrase
如果您使用的是Linux/Mac,那么您可以删除文件known_hosts。
它位于~/.ssh/known_hosts,或者如果您想覆盖/删除特定的 ssh 主机,那么您可以编辑 known_hosts 文件。
查看所有主机 => cat ~/.ssh/known_hosts
删除 know_hosts 文件 => rm -rf ~/.ssh/known_hosts
【讨论】:
如果您生成了一个带有密码的 SSH 密钥,然后您忘记了此 SSH 密钥的密码,无法恢复它,您需要生成一个全新的 SSH 密钥对或切换到 HTTPS 克隆,以便您可以使用 GitHub 密码。
如果您使用 OS X 钥匙串配置了 SSH 密码,您或许可以恢复它。
【讨论】:
密码短语可以添加到现有密钥中,也可以在不重新生成密钥对的情况下更改:
注意如果密钥没有密码短语,这将起作用,否则您会得到:@ 987654322@ 然后Bad passphrase
$ ssh-keygen -p
Enter file in which the key is (/Users/tekkub/.ssh/id_rsa):
Key has comment '/Users/tekkub/.ssh/id_rsa'
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
如果您的密钥有passphrase,那么无法恢复一对 SSH 密钥的密码。在这种情况下,您必须创建一对新的 SSH 密钥。
【讨论】:
Enter old passphrase:然后Bad passphrase.
简而言之,没有办法恢复一对 SSH 密钥的密码。为什么?因为出于安全原因,它首先是这样设计的。其他人给你的答案都是更改密钥密码的正确方法,而不是恢复它们。因此,如果您忘记了密码,最好的办法就是创建一对新的 SSH 密钥。这里是how to generate SSH keys and add it to your GitHub account。
【讨论】:
【讨论】:
您可以通过以下方式更改您的私钥的密码:
ssh-keygen -f ~/.ssh/id_rsa -p
【讨论】:
~/.ssh/id_rsa 本身没有加密,不是吗?但如果它是加密的,我们又回到了原点。