如何将使用 PuTTYgen (Windows) 生成的 SSH 密钥对转换为 ssh-agent 和 Keychain (Linux) 使用的密钥对

发布于 2024-08-21 06:03:18 字数 187 浏览 6 评论 0原文

我已使用 PuTTYgen 生成密钥对并使用 Pageant 登录,因此系统启动时只需输入一次密码。

我如何在 Linux 中实现这一点?我听说过keychain,但我听说它使用不同的密钥对格式 - 我不想更改我的 Windows 密钥,如果我能够以相同的方式无缝连接,那就太好了Windows 和 Linux 均可。

I've generated key pairs using PuTTYgen and been logging in using Pageant, so that I have to enter my pass-phrase only once when my system boots.

How do I achieve this in Linux? I've heard of keychain but I hear that it uses a different key pair format - I don't want to change my Windows keys and it would be nice if I could seamlessly connect in the same manner in both Windows and Linux.

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

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

发布评论

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

评论(10

提赋 2024-08-28 06:03:19

较新版本的 PuTTYgen (我的是 0.64)能够在 .ssh/authorized_keys 文件中显示要粘贴到 Linux 系统中的 OpenSSH 公钥,如下图所示:

在此处输入图像描述

Newer versions of PuTTYgen (mine is 0.64) are able to show the OpenSSH public key to be pasted in the linux system in the .ssh/authorized_keys file, as shown in the following image:

enter image description here

老子叫无熙 2024-08-28 06:03:19

或者,如果您想从 PuTTY 格式的密钥文件中获取私钥和​​公钥,您可以在 *nix 系统上使用 puttygen。对于大多数基于 apt 的系统,puttygen 是 putty-tools 包的一部分。

从 PuTTY 格式的密钥文件输出私钥:

$ puttygen keyfile.pem -O private-openssh -o avdev.pvk

对于公钥:

$ puttygen keyfile.pem -L

Alternatively if you want to grab the private and public keys from a PuTTY formated key file you can use puttygen on *nix systems. For most apt-based systems puttygen is part of the putty-tools package.

Outputting a private key from a PuTTY formated keyfile:

$ puttygen keyfile.pem -O private-openssh -o avdev.pvk

For the public key:

$ puttygen keyfile.pem -L

一影成城 2024-08-28 06:03:19
sudo apt-get install putty

这将自动安装 puttygen 工具。

现在要转换要与 SSH 命令一起使用的 PPK 文件,请在终端中执行以下命令

puttygen mykey.ppk -O private-openssh -o my-openssh-key

然后,您可以通过 SSH 连接:

ssh -v [email protected] -i my-openssh-key

http://www.graphicmist.in/use-your-putty-ppk-file-to-ssh-remote-服务器在ubuntu/#comment-28603

sudo apt-get install putty

This will automatically install the puttygen tool.

Now to convert the PPK file to be used with SSH command execute the following in terminal

puttygen mykey.ppk -O private-openssh -o my-openssh-key

Then, you can connect via SSH with:

ssh -v [email protected] -i my-openssh-key

http://www.graphicmist.in/use-your-putty-ppk-file-to-ssh-remote-server-in-ubuntu/#comment-28603

最近可好 2024-08-28 06:03:19

我最近在从 Putty for Linux 迁移到 Remmina for Linux 时遇到了这个问题。因此,我的 .putty 目录中有很多 Putty 的 PPK 文件,因为我已经使用 Putty 8 年了。为此,我使用了 bash shell 的一个简单的 for 命令来处理所有文件:

cd ~/.putty
for X in *.ppk; do puttygen $X -L > ~/.ssh/$(echo $X | sed 's,./,,' | sed 's/.ppk//g').pub; puttygen $X -O private-openssh -o ~/.ssh/$(echo $X | sed 's,./,,' | sed 's/.ppk//g').pvk; done;

非常快速且切中要害,完成了 putty 拥有的所有文件的工作。如果它发现带有密码的密钥,它将停止并首先询问该密钥的密码,然后继续。

I recently had this problem as I was moving from Putty for Linux to Remmina for Linux. So I have a lot of PPK files for Putty in my .putty directory as I've been using it's for 8 years. For this I used a simple for command for bash shell to do all files:

cd ~/.putty
for X in *.ppk; do puttygen $X -L > ~/.ssh/$(echo $X | sed 's,./,,' | sed 's/.ppk//g').pub; puttygen $X -O private-openssh -o ~/.ssh/$(echo $X | sed 's,./,,' | sed 's/.ppk//g').pvk; done;

Very quick and to the point, got the job done for all files that putty had. If it finds a key with a password it will stop and ask for the password for that key first and then continue.

阪姬 2024-08-28 06:03:19

在 Linux 下创建密钥并使用 PuTTYgen 将密钥转换为 PuTTY 格式可能更容易。

PuTTY 常见问题解答:A.2.2

It's probably easier to create your keys under linux and use PuTTYgen to convert the keys to PuTTY format.

PuTTY Faq: A.2.2

莫多说 2024-08-28 06:03:19

我认为 TCSgrad(几年前)试图问的是如何让 Linux 的行为就像他的 Windows 机器一样。也就是说,有一个代理(选美)持有私钥的解密副本,因此密码只需输入一次。然后,ssh 客户端 putty 可以登录其公钥被列为“已授权”的计算机,而无需密码提示。

与此类似的是,Linux充当 ssh 客户端,有一个代理持有解密的私钥,这样当 TCSgrad 键入“ssh 主机”时,ssh 命令将获取他的私钥,并且无需被加密。提示输入密码。当然,主机必须将公钥保存在 ~/.ssh/authorized_keys 中。

Linux 对此场景的模拟是使用 ssh-agent (选美模拟)和 ssh-add (模拟向选美添加私钥)来完成的。

对我有用的方法是使用:
$ ssh-agent $SHELL
$SHELL 是我让代理运行并保持运行所需的魔术。我在网上的某个地方发现了这一点,这结束了我几个小时的头撞墙。

现在我们有一个类似选美比赛的运行​​,一个没有加载密钥的代理。

打字
$ ssh-添加
其本身将添加(默认情况下) ~/.ssh 中默认身份文件中列出的私钥。

可以在此处找到包含更多详细信息的网络文章

I think what TCSgrad was trying to ask (a few years ago) was how to make Linux behave like his Windows machine does. That is, there is an agent (pageant) which holds a decrypted copy of a private key so that the passphrase only needs to be put in once. Then, the ssh client, putty, can log in to machines where his public key is listed as "authorized" without a password prompt.

The analog for this is that Linux, acting as an ssh client, has an agent holding a decrypted private key so that when TCSgrad types "ssh host" the ssh command will get his private key and go without being prompted for a password. host would, of course, have to be holding the public key in ~/.ssh/authorized_keys.

The Linux analog to this scenario is accomplished using ssh-agent (the pageant analog) and ssh-add (the analog to adding a private key to pageant).

The method that worked for me was to use:
$ ssh-agent $SHELL
That $SHELL was the magic trick I needed to make the agent run and stay running. I found that somewhere on the 'net and it ended a few hours of beating my head against the wall.

Now we have the analog of pageant running, an agent with no keys loaded.

Typing
$ ssh-add
by itself will add (by default) the private keys listed in the default identity files in ~/.ssh .

A web article with a lot more details can be found here

近箐 2024-08-28 06:03:19

PPK → OpenSSH RSA 与 PuttyGen &码头工人。

私钥:

docker run --rm -v $(pwd):/app zinuzoid/puttygen private.ppk -O private-openssh -o my-openssh-key

公钥:

docker run --rm -v $(pwd):/app zinuzoid/puttygen private.ppk -L -o my-openssh-key.pub

另请参阅 https://hub.docker.com/r/zinuzoid/普蒂根

PPK → OpenSSH RSA with PuttyGen & Docker.

Private key:

docker run --rm -v $(pwd):/app zinuzoid/puttygen private.ppk -O private-openssh -o my-openssh-key

Public key:

docker run --rm -v $(pwd):/app zinuzoid/puttygen private.ppk -L -o my-openssh-key.pub

See also https://hub.docker.com/r/zinuzoid/puttygen

天涯沦落人 2024-08-28 06:03:19

甚至比重新打开 puttygen 还要快,我经常做的是:

  1. 复制公钥文件。
  2. 在副本中,将“ssh-rsa”一词放在开头。
  3. 删除开始/结束注释行和所有其他换行符。
  4. 节省。结果是一个适用于 openssh 的单行密钥。

Even faster than reopening puttygen, what I have often done is:

  1. Duplicate the public key file.
  2. In the copy, place the word "ssh-rsa " at the beginning.
  3. Remove the begin/end comment lines and all other line breaks.
  4. Save. The result is a one line key that works for openssh.
Bonjour°[大白 2024-08-28 06:03:18

puttygen 支持将私钥导出为 OpenSSH 兼容格式。然后,您可以使用 OpenSSH 工具重新创建公钥。

  1. 打开 PuttyGen
  2. 点击 Load
  3. 加载您的私钥
  4. 转到 Conversions->Export OpenSSH 并导出您的私钥
  5. 将您的私钥复制到 ~/.ssh/id_dsa (或 id_rsa)。
  6. 使用 ssh-keygen 创建 RFC 4716 版本的公钥

    ssh-keygen -e -f ~/.ssh/id_dsa > 〜/.ssh/id_dsa_com.pub
    
  7. 将 RFC 4716 版本的公钥转换为 OpenSSH 格式:

    ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > 〜/.ssh/id_dsa.pub
    

请参阅 了解更多信息。

puttygen supports exporting your private key to an OpenSSH compatible format. You can then use OpenSSH tools to recreate the public key.

  1. Open PuttyGen
  2. Click Load
  3. Load your private key
  4. Go to Conversions->Export OpenSSH and export your private key
  5. Copy your private key to ~/.ssh/id_dsa (or id_rsa).
  6. Create the RFC 4716 version of the public key using ssh-keygen

    ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub
    
  7. Convert the RFC 4716 version of the public key to the OpenSSH format:

    ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub
    

See this and this for more information.

我不会写诗 2024-08-28 06:03:18

如果您拥有的只是 PuTTY 样式格式的用户公钥,您可以将其转换为标准 openssh 格式,如下所示:

ssh-keygen -i -f keyfile.pub > newkeyfile.pub

参考资料

文章副本

我总是忘记这一点,所以我会把它写在这里。非极客,只是
继续走。

在 Windows 上创建密钥的最常见方法是使用 Putty/Puttygen。
Puttygen 提供了一个简洁的实用程序来将 Linux 私钥转换为
腻子格式。但是,没有解决的是,当您保存
使用 puttygen 的公钥在 Linux 服务器上不起作用。视窗
将一些数据放在不同的区域并添加换行符。

解决方案:当您进入创建公钥屏幕时
puttygen 中的密钥对,复制公钥并将其粘贴到文本中
扩展名为 .pub 的文件。您将为系统管理员节省时间
读这样的帖子很沮丧。

但是,系统管理员,您总是会得到抛出异常的不稳定密钥文件
身份验证日志中没有错误消息,除了找不到密钥,正在尝试
密码;即使其他人的钥匙都工作正常,并且
您已将此密钥发送回用户 15 次。

ssh-keygen -i -f keyfile.pub >新密钥文件.pub

应将现有的 puttygen 公钥转换为 OpenSSH 格式。

If all you have is a public key from a user in PuTTY-style format, you can convert it to standard openssh format like so:

ssh-keygen -i -f keyfile.pub > newkeyfile.pub

References

Copy of article

I keep forgetting this so I'm gonna write it here. Non-geeks, just
keep walking.

The most common way to make a key on Windows is using Putty/Puttygen.
Puttygen provides a neat utility to convert a linux private key to
Putty format. However, what isn't addressed is that when you save the
public key using puttygen it won't work on a linux server. Windows
puts some data in different areas and adds line breaks.

The Solution: When you get to the public key screen in creating your
key pair in puttygen, copy the public key and paste it into a text
file with the extension .pub. You will save you sysadmin hours of
frustration reading posts like this.

HOWEVER, sysadmins, you invariably get the wonky key file that throws
no error message in the auth log except, no key found, trying
password; even though everyone else's keys are working fine, and
you've sent this key back to the user 15 times.

ssh-keygen -i -f keyfile.pub > newkeyfile.pub

Should convert an existing puttygen public key to OpenSSH format.

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