如何验证/检查/测试/验证我的 SSH 密码?
我想我忘记了 SSH 密钥的密码,但我有预感它可能是什么。我如何检查我是否正确?
I think I forgot the passphrase for my SSH key, but I have a hunch what it might be. How do I check if I'm right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
ssh-keygen -y
将提示您输入密码(如果有)。如果您输入正确密码,它将显示关联的公钥。
如果您输入错误密码,将会显示
加载失败
。如果密钥没有密码,它将不会提示您输入密码,并会立即向您显示关联的公钥。
请注意,参数的顺序很重要。
-y
必须出现在-f input_keyfile
之前,否则您将收到错误Too mucharguments.
例如,
创建一个新的公钥/私钥对,带或不带密码:
现在看看您是否可以访问该密钥对:
Following are extended examples, with example output.
使用密码的行为:
首先,创建一个新的公钥/私钥对,带有密码:
现在尝试通过输入正确的密码来访问密钥对。
请注意,将显示公钥,退出状态 (
$?
) 将为0
表示成功:现在尝试通过输入 来访问密钥对密码错误。
请注意,将显示
load failed
错误消息(消息可能因操作系统而异),并且退出状态 ($?
) 将为1
指示错误:没有密码的行为:
首先,创建一个新的公钥/私钥对,没有密码:
现在尝试访问该密钥对。请注意,没有提示输入密码,将显示公钥,退出状态 (
$?
) 将为0
表示成功:ssh-keygen -y
will prompt you for the passphrase (if there is one).If you input the correct passphrase, it will show you the associated public key.
If you input the wrong passphrase, it will display
load failed
.If the key has no passphrase, it will not prompt you for a passphrase and will immediately show you the associated public key.
Note that the order of arguments is important.
-y
must come before-f input_keyfile
, else you will get the errorToo many arguments.
e.g.,
Create a new public/private key pair, with or without a passphrase:
Now see if you can access the key pair:
Following are extended examples, with example output.
Behavior with a passphrase:
First, create a new public/private key pair, with a passphrase:
Now attempt to access the key pair by inputting the correct passphrase.
Note that the public key will be shown and the exit status (
$?
) will be0
to indicate success:Now attempt to access the key pair by inputting an incorrect passphrase.
Note that the
load failed
error message will be displayed (message may differ depending on OS) and the exit status ($?
) will be1
to indicate an error:Behavior with no passphrase:
First, create a new public/private key pair, without a passphrase:
Now attempt to access that key pair. Note that there is no prompt for the passphrase, the public key will be displayed, and the exit status (
$?
) will be0
to indicate success:您可以通过尝试将 SSH 密钥密码加载到 SSH 代理来验证它。对于 OpenSSH,这是通过
ssh-add
完成的。完成后,请记住通过运行 ssh-add -d 从终端卸载 SSH 密码。
You can verify your SSH key passphrase by attempting to load it into your SSH agent. With OpenSSH this is done via
ssh-add
.Once you're done, remember to unload your SSH passphrase from the terminal by running
ssh-add -d
.到目前为止,我在网上找到的最佳答案是:
这将尝试使用密码作为空字符串读取私钥。如果您的密钥没有密码短语,那么这将完美地显示公钥。
否则应用程序将退出并显示错误代码和消息:
The best answer so far, that I found on the web is:
That will attempt to read the private key with the passphrase as empty string. That will show a public key perfectly fine if you have a key with no passphrase.
Otherwise the app will exit with an error code and the message:
将 @RobBednark 的解决方案扩展到特定的 Windows + PuTTY 场景,您可以这样做:
使用 PuTTYgen 生成 SSH 密钥对(遵循在 Windows 中手动生成 SSH 密钥< /em>),将其保存到 PPK 文件;
通过 Windows 资源管理器中的上下文菜单,选择“使用 PuTTYgen 进行编辑”。它将提示输入密码。
如果您输入错误的密码,它只会再次提示。
请注意,如果您想键入,请在包含 PPK 文件的文件夹上使用以下命令:
puttygen private-key.ppk -y
。Extending @RobBednark's solution to a specific Windows + PuTTY scenario, you can do so:
Generate SSH key pair with PuTTYgen (following Manually generating your SSH key in Windows), saving it to a PPK file;
With the context menu in Windows Explorer, choose Edit with PuTTYgen. It will prompt for a password.
If you type the wrong password, it will just prompt again.
Note, if you like to type, use the following command on a folder that contains the PPK file:
puttygen private-key.ppk -y
.使用“ssh-keygen -p”。您可以添加“-f”,
它会提示您输入旧密码。如果密码正确,会提示输入新密码。如果旧密码不正确,您将收到“无法加载密钥<...>”。
Use "ssh-keygen -p". You can add "-f "
It will prompt you for the old password. If the password is correct, it will prompt to enter a new password. If the old password is incorrect, you will get "Failed to load key <...>".
如果您的密码是解锁 SSH 密钥,并且您没有
ssh-agent
,但计算机上安装了 sshd(SSH 守护进程),请执行以下操作:其中
~/.ssh /id_rsa.pub
是公钥,~/.ssh/id_rsa
是私钥。If your passphrase is to unlock your SSH key and you don't have
ssh-agent
, but do have sshd (the SSH daemon) installed on your machine, do:Where
~/.ssh/id_rsa.pub
is the public key, and~/.ssh/id_rsa
is the private key.