2010-09-29 63 views
142

我使用puttygen生成OpenSSH私钥(并以OpenSSH格式导出它)。我怎样才能在这个现有的密钥(我知道如何生成一个新的密码与密码)的密码?如何将密码添加到未经密码生成的OpenSSH私钥?

+12

如果您看到此评论,请将其中一个答案标记为已接受或写下评论,说明他们错过了什么。谢谢! – 2011-11-18 22:26:03

+0

添加和更改或删除相同:http://stackoverflow.com/questions/112396/how-do-i-remove-the-passphrase-for-the-ssh-key-without-having-to-create-一个新的科,可能相同的变化:http://serverfault.com/questions/50775/how-do-i-change-my-private-key-passphrase – 2015-04-02 08:04:34

+0

如果你得到***'坏密码短语* * **在'id_ed25519'键上,但密码是正确的,那么你可能使用低级的'ssh-keygen'来管理它。 – jww 2015-08-27 22:07:00

回答

227

尝试命令ssh-keygen -p -f keyfile

从SSH-keygen手册页

-p  Requests changing the passphrase of a private key file instead of 
     creating a new private key. The program will prompt for the file 
     containing the private key, for the old passphrase, and twice for 
     the new passphrase. 

-f filename 
     Specifies the filename of the key file. 

例子:

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

对于那些想知道什么-f是:它指定输入文件。 – Neikos 2015-12-11 10:49:14

+1

//,@sigjuice,请你举个例子,比如'$ ssh-keygen -p -f/Users/sigjuice/.ssh/id_rsa'?这可能会帮助那些不知道如何区分公钥和私钥之间的差异,并帮助他们更快地弄湿脚的人。 – 2016-07-06 18:48:52

25

使用-p选项到ssh-凯基。这允许您更改密码而不是生成新密钥。

更改密码sigjuice显示:

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

所需的密码将成为新的密码。 (这是假设你已经添加了公钥~/.ssh/id_rsa.pub您的authorized_keys文件。)测试使用SSH

ssh -i ~/.ssh/id_rsa localhost 

你可以有不同的用途,不同名称的多个按键。

+0

//,请您举例说明一下,以及如何检查该选项是否有效,@BillThor? – 2016-07-06 18:49:24

+1

@NathanBasanese查看编辑的回复。 – BillThor 2016-07-06 19:47:21