git 如何重置或更改 GitHub SSH 密钥的密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10189745/
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-10 13:29:00  来源:igfitidea点击:

How to reset or change the passphrase for a GitHub SSH key?

gitgithubsshssh-keyspassphrase

提问by Tech MLG

I have forgoten my passphrase in Git. How do I reset it? I found two solutions on Stack Overflow, but I want to know what process to follow to reset it or to get it.

我忘记了我在 Git 中的密码。如何重置?我在 Stack Overflow 上找到了两个解决方案,但我想知道要遵循什么流程来重置或获取它。

回答by manojlds

You can change the passphrase for your private key by doing:

您可以通过执行以下操作来更改私钥的密码:

ssh-keygen -f ~/.ssh/id_rsa -p

回答by Metafaniel

In short there's no way to recoverthe passphrase for a pair of SSH keys. Why? Because it was intended this way in the first place for security reasons. The answers the other people gave you are all correct ways to CHANGE the password of your keys, not to recoverthem. So if you've forgotten your passphrase, the best you can do is create a new pair of SSH keys. Here's how to generate SSH keys and add it to your GitHub account.

简而言之,无法恢复一对 SSH 密钥的密码。为什么?因为出于安全原因,它首先是这样设计的。其他人给您的答案都是更改密钥密码的正确方法,而不是恢复它们。因此,如果您忘记了密码,您能做的最好的事情就是创建一对新的 SSH 密钥。以下是如何生成 SSH 密钥并将其添加到您的 GitHub 帐户

回答by liangzr

If you had generate a SSH-key with passphrase and then you forget your passphrase for this SSH-key,there's no way to recover it, You'll need to generate a brand new SSH keypair or switch to HTTPS cloning so you can use your GitHub password instead.

如果您使用密码生成了 SSH 密钥,然后您忘记了此 SSH 密钥的密码,则无法恢复它,您需要生成一个全新的 SSH 密钥对或切换到 HTTPS 克隆,以便您可以使用您的GitHub 密码。

BUT,there are exceptions

但是,也有例外

If you configured your SSH passphrase with the OS XKeychain, you may be able to recover it.

如果您使用OS X钥匙串配置了 SSH 密码,则可以恢复它。

  1. In Finder, search for the Keychain Access app.
  2. In Keychain Access, search for SSH.
  3. Double click on the entry for your SSH key to open a new dialog box.
  4. Keychain access dialogIn the lower-left corner, select Show password.
  5. You'll be prompted for your administrative password. Type it into the "Keychain Access" dialog box.
  6. Your password will be revealed.
  1. 在 Finder 中,搜索 Keychain Access 应用程序。
  2. 在钥匙串访问中,搜索 SSH。
  3. 双击 SSH 密钥条目以打开一个新对话框。
  4. 钥匙串访问对话框在左下角,选择显示密码。
  5. 系统会提示您输入管理密码。在“钥匙串访问”对话框中输入它。
  6. 您的密码将被泄露。

Refer to Github help - How do I recover my SSH key passphrase?

请参阅Github 帮助 - 如何恢复我的 SSH 密钥密码?

回答by Sumit Singh

Passphrases can be added to an existing key or changed without regenerating the key pair:
NoteThis will work if keys doesn't had a passphrase, otherwise you'll get this: Enter old passphrase:then Bad passphrase

可以将密码添加到现有密钥或更改而不重新生成密钥对:
注意如果密钥没有密码,这将起作用,否则您会得到:Enter old passphrase:然后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.

If your key had passphrasethen, There's no way to recover the passphrase for a pair of SSH keys.In that case you have to create a new pair of SSH keys.

如果您的密钥当时有,passphrase无法恢复一对 SSH 密钥的密码。在这种情况下,您必须创建一对新的 SSH 密钥。

  1. Generating SSH keys
  1. 生成 SSH 密钥

回答by kostix

  1. Log in to your github account.
  2. Go to the "Settings" page (the "wrench and screwdriver" icon in the top right corner of the page).
  3. Go to "SSH keys" page.
  4. Generate a new SSH key (probably studying the links provided by github on that page).
  5. Add your new key using the "Add SSH key" link.
  6. Verify your new key works.
  7. Make gitub forget your old key by using the "Delete" link next to it in the list of known keys.
  1. 登录到您的 github 帐户。
  2. 转到“设置”页面(页面右上角的“扳手和螺丝刀”图标)。
  3. 转到“SSH 密钥”页面。
  4. 生成一个新的 SSH 密钥(可能正在研究该页面上 github 提供的链接)。
  5. 使用“添加 SSH 密钥”链接添加新密钥。
  6. 验证您的新密钥是否有效。
  7. 通过使用已知密钥列表中它旁边的“删除”链接,让 gitub 忘记你的旧密钥。