如何删除 SSH 密钥的密码而无需创建新密钥?

发布于 2024-07-06 21:33:50 字数 330 浏览 12 评论 0原文

我在笔记本电脑上创建新的 SSH 密钥时设置了密码。 但是,正如我现在意识到的那样,当您尝试提交时,这是相当痛苦的(Git 和 SVN) 在一个小时内通过 SSH 多次发送到远程位置。

我能想到的一种方法是删除我的 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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

不再见 2024-07-13 21:33:50

简短回答:

$ ssh-keygen -p

然后,这将提示您输入密钥文件位置、旧密码和新密码(可以留空以没有密码)。


如果您想在没有提示的情况下在一行上完成所有操作,请执行以下操作:

$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]

重要: 请注意,执行命令时它们通常会记录在您的 ~/.bash_history 文件中(或类似)以纯文本形式,包括提供的所有参数(即本例中的密码短语)。 因此,建议您使用第一个选项,除非您有特殊原因不这样做。

请注意,您仍然可以使用 -f keyfile 而不必指定 -P-N,并且密钥文件默认为 ~/.ssh/id_rsa,所以在很多情况下,甚至不需要它。

您可能需要考虑使用 ssh-agent,它可以暂时缓存密码。 最新版本的 gpg-agent 还支持 ssh-agent 使用的协议。

Short answer:

$ 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]

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.

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.

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.

在你怀里撒娇 2024-07-13 21:33:50

$ ssh-keygen -p 为我工作

打开了 git bash。 粘贴:$ ssh-keygen -p

按 Enter 键进入默认位置。

输入旧密码

输入新密码 - BLANK

确认新密码 - BLANK

BOOM 输入 git Push 密码的痛苦消失了。

谢谢!

$ ssh-keygen -p worked for me

Opened git bash. Pasted : $ ssh-keygen -p

Hit enter for default location.

Enter old passphrase

Enter new passphrase - BLANK

Confirm new passphrase - BLANK

BOOM the pain of entering passphrase for git push was gone.

Thanks!

没有伤那来痛 2024-07-13 21:33:50

您可能需要将以下内容添加到您的 .bash_profile (或等效文件)中,以便在登录时启动 ssh-agent 。

if [ -f ~/.agent.env ] ; then
    . ~/.agent.env > /dev/null
    if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then
        echo "Stale agent file found. Spawning new agent… "
        eval $(ssh-agent | tee ~/.agent.env)
        ssh-add
    fi 
else
    echo "Starting ssh-agent"
    eval $(ssh-agent | tee ~/.agent.env)
    ssh-add
fi

在某些 Linux 发行版(Ubuntu、Debian)上,您可以使用:

ssh-copy-id -i ~/.ssh/id_dsa.pub username@host

这会将生成的 id 复制到远程计算机并将其添加到远程钥匙串中。

您可以在此处此处

You might want to add the following to your .bash_profile (or equivalent), which starts ssh-agent on login.

if [ -f ~/.agent.env ] ; then
    . ~/.agent.env > /dev/null
    if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then
        echo "Stale agent file found. Spawning new agent… "
        eval $(ssh-agent | tee ~/.agent.env)
        ssh-add
    fi 
else
    echo "Starting ssh-agent"
    eval $(ssh-agent | tee ~/.agent.env)
    ssh-add
fi

On some Linux distros (Ubuntu, Debian) you can use:

ssh-copy-id -i ~/.ssh/id_dsa.pub username@host

This will copy the generated id to a remote machine and add it to the remote keychain.

You can read more here and here.

∞觅青森が 2024-07-13 21:33:50

要更改或删除密码,我经常发现最简单的方法是仅传入 pf 标志,然后让系统提示我提供密码:

ssh-keygen -p -f

例如:

ssh-keygen -p -f id_rsa

如果要删除密码,请输入空密码。

删除或更改密码的示例运行如下所示:

ssh-keygen -p -f id_rsa
Enter old passphrase: 
Key has comment 'bcuser@pl1909'
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase.

将密码短语添加到没有密码短语的密钥时,运行如下所示:

ssh-keygen -p -f id_rsa
Key has comment 'charlie@elf-path'
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase.

To change or remove the passphrase, I often find it simplest to pass in only the p and f flags, then let the system prompt me to supply the passphrases:

ssh-keygen -p -f <name-of-private-key>

For instance:

ssh-keygen -p -f id_rsa

Enter an empty password if you want to remove the passphrase.

A sample run to remove or change a password looks something like this:

ssh-keygen -p -f id_rsa
Enter old passphrase: 
Key has comment 'bcuser@pl1909'
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase.

When adding a passphrase to a key that has no passphrase, the run looks something like this:

ssh-keygen -p -f id_rsa
Key has comment 'charlie@elf-path'
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase.
喜你已久 2024-07-13 21:33:50

Mac 上,您可以将 ssh 私钥的密码存储在钥匙串中,这使得它的使用变得透明。 如果您已登录,则它可用,当您注销时,您的 root 用户将无法使用它。 删除密码是一个坏主意,因为拥有该文件的任何人都可以使用它。

ssh-keygen -K

将其添加到 ~/.ssh/config

UseKeychain yes

On the Mac you can store the passphrase for your private ssh key in your Keychain, which makes the use of it transparent. If you're logged in, it is available, when you are logged out your root user cannot use it. Removing the passphrase is a bad idea because anyone with the file can use it.

ssh-keygen -K

Add this to ~/.ssh/config

UseKeychain yes
丿*梦醉红颜 2024-07-13 21:33:50

对于 Mac 上的我来说,以下步骤解决了问题。

1> 打开终端,转到用户目录并输入以下命令。

ssh-keygen -p

2> 它会问你

输入密钥为(/Users/您的用户名/.ssh/id_rsa)的文件:
给出圆括号中显示的文件路径。

3> 然后它会要求您输入旧密码。 写下您的旧密码并输入。 当您输入密码时,终端不会显示任何内容。

4> 它会要求您输入新密码

输入新密码(空表示无密码)
如果您不想保留任何密码,只需按 Enter 键即可。

5> 然后它会再次要求您确认相同的密码

再次输入相同的密码
然后再次按 Enter 键。

6> 然后你会收到成功消息

您的身份信息已使用新密码保存。

For me on Mac below steps solved the problem.

1> open a terminal go to users directory and enter the below command.

ssh-keygen -p

2> It will ask you

Enter file in which the key is (/Users/your user name/.ssh/id_rsa):
give the file path which is shown in the round brackets.

3> Then it will ask you to enter the old passphrase. Write your old passphrase and enter. When you enter the passphrase terminal will not show anything.

4> The it will ask you to enter the new passphrase

Enter new passphrase (empty for no passphrase)
If you don't want to keep any passphrase then just press enter.

5> Then again it will ask you to confirm the same passphrase

Enter same passphrase again
Then again press enter.

6> Then you will get success message

Your identification has been saved with the new passphrase.

梦毁影碎の 2024-07-13 21:33:50

在 Windows 上,您可以使用 PuttyGen 加载私钥文件,删除密码,然后覆盖现有私钥文件。

On windows, you can use PuttyGen to load the private key file, remove the passphrase and then overwrite the existing private key file.

想念有你 2024-07-13 21:33:50

在我的窗户上它一直说
输入上述命令后,“id_ed25135:没有这样的文件或目录”。 所以我转到该文件夹​​,复制文件夹资源管理器中的路径并在末尾添加“\id_ed25135”。

这就是我最终输入并工作的内容:
ssh-keygen -p -f C:\Users\john\.ssh\id_ed25135

这有效。 因为由于某种原因,在 Cmder 中默认路径是这样的 C:\Users\capit/.ssh/id_ed25135 (有些是反斜杠:“\”,有些是正斜杠:“/”)

In windows for me it kept saying
"id_ed25135: No such file or directory" upon entering above commands. So I went to the folder, copied the path within folder explorer and added "\id_ed25135" at the end.

This is what I ended up typing and worked:
ssh-keygen -p -f C:\Users\john\.ssh\id_ed25135

This worked. Because for some reason, in Cmder the default path was something like this C:\Users\capit/.ssh/id_ed25135 (some were backslashes: "\" and some were forward slashes: "/")

栩栩如生 2024-07-13 21:33:50

对于 Windows;

  1. 打开一个cmd屏幕,写下这个并按回车键。

    ssh-keygen -p

  2. cmd 会询问您旧的密码。 写下您的旧密码并输入。 当您写入旧密码时,您看不到它。

  3. cmd 将询问您新的密码并进行确认。 您可以将其留空。

恭喜!!!

For Windows;

  1. open a cmd screen write this and push enter.

    ssh-keygen -p

  2. cmd will ask you the old passphrase. Write your old passphrase and enter. You can't see the old passphrase when you write it.

  3. cmd will ask you the new passphrase and its confirmation. You can let it blank.

Congratulations!!!

潜移默化 2024-07-13 21:33:50

如果您之前设置过密码并且正在使用 mac,请改用钥匙串,您需要最后一次输入密码,仅此而已

ssh-add --apple-use-keychain ~/.ssh/id_rsa
Enter passphrase for /Users/{{user_name}}/.ssh/id_rsa:
Identity added: /Users/{{user_name}}/.ssh/id_rsa(/Users/{{user_name}}/.ssh/id_rsa)

If you have set a passphrase before and is using mac, use the keychain instead, you'll need to enter your passpharase for the last time and that's it

ssh-add --apple-use-keychain ~/.ssh/id_rsa
Enter passphrase for /Users/{{user_name}}/.ssh/id_rsa:
Identity added: /Users/{{user_name}}/.ssh/id_rsa(/Users/{{user_name}}/.ssh/id_rsa)
毅然前行 2024-07-13 21:33:50

如果您使用的是 Mac,

  • 请转至 .ssh 文件夹,
  • 通过添加“UseKeychain yes”更新配置文件

If you are using Mac

  • Go to .ssh folder
  • update config file by adding "UseKeychain yes"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文