问题描述
在笔记本电脑上创建新的SSH密钥时,我设置了密码.但是,正如我现在意识到的那样,当您尝试提交时( Git 和 SVN )在一小时内通过SSH多次到达远程位置.
I set a passphrase when creating a new SSH key on my laptop. But, as I realise now, this is quite painful when you are trying to commit (Git and SVN) to a remote location over SSH many times in an hour.
我能想到的一种方法是删除我的SSH密钥并创建新的.有没有办法删除密码短语,同时仍然保持相同的密钥?
One way I can think of is, delete my SSH keys and create new. Is there a way to remove the passphrase, while still keeping the same keys?
推荐答案
简短答案:
$ ssh-keygen -p
然后,这将提示您输入密钥文件位置,旧密码和新密码(可以将其保留为空白而没有密码).
This will then prompt you to enter the keyfile location, the old passphrase, and the new passphrase (which can be left blank to have no passphrase).
如果您希望在没有提示的情况下一行全部完成操作,请执行以下操作:
If you would like to do it all on one line without prompts do:
$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
重要提示::请注意,执行命令时,它们通常会以纯文本格式(包括本例中的密码)记录在您的~/.bash_history
文件(或类似文件)中.因此,除非有特殊原因,否则建议您使用第一个选项.
Important: Beware that when executing commands they will typically be logged in your ~/.bash_history
file (or similar) in plain text including all arguments provided (i.e. the passphrases in this case). It is, therefore, is recommended that you use the first option unless you have a specific reason to do otherwise.
请注意,尽管您仍可以使用-f keyfile
而不需要指定-P
或-N
,并且密钥文件默认为~/.ssh/id_rsa
,所以在很多情况下,甚至不需要它.
Notice though that you can still use -f keyfile
without having to specify -P
nor -N
, and that the keyfile defaults to ~/.ssh/id_rsa
, so in many cases, it's not even needed.
您可能要考虑使用ssh-agent,它可以将密码短语缓存一段时间.最新版本的gpg-agent还支持ssh-agent使用的协议.
You might want to consider using ssh-agent, which can cache the passphrase for a time. The latest versions of gpg-agent also support the protocol that is used by ssh-agent.
这篇关于如何在不创建新密钥的情况下删除SSH密钥的密码短语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!