git 如何将使用 PuTTYgen (Windows) 生成的 SSH 密钥对转换为 ssh-agent 和 Keychain (Linux) 使用的密钥对
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2224066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert SSH keypairs generated using PuTTYgen (Windows) into key-pairs used by ssh-agent and Keychain (Linux)
提问by TCSGrad
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.
我已经使用 PuTTYgen 生成了密钥对并使用 Pageant 登录,因此我只需要在系统启动时输入一次密码短语。
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.
我如何在 Linux 中实现这一点?我听说过,keychain
但我听说它使用不同的密钥对格式 - 我不想更改我的 Windows 密钥,如果我可以在 Windows 和 Linux 中以相同的方式无缝连接,那就太好了。
回答by Kaleb Pederson
puttygen
supports exporting your private key to an OpenSSH compatible format. You can then use OpenSSH tools to recreate the public key.
puttygen
支持将您的私钥导出为 OpenSSH 兼容格式。然后,您可以使用 OpenSSH 工具重新创建公钥。
- Open PuttyGen
- Click Load
- Load your private key
- Go to
Conversions->Export OpenSSH
and export your private key - Copy your private key to
~/.ssh/id_dsa
(orid_rsa
). Create the RFC 4716 version of the public key using
ssh-keygen
ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub
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
- 打开 PuttyGen
- 点击加载
- 加载你的私钥
- 转到
Conversions->Export OpenSSH
并导出您的私钥 - 将您的私钥复制到
~/.ssh/id_dsa
(或id_rsa
)。 使用创建公钥的 RFC 4716 版本
ssh-keygen
ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub
将 RFC 4716 版本的公钥转换为 OpenSSH 格式:
ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub
回答by bukzor
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:
如果您拥有的是来自用户的 PuTTY 样式格式的公钥,则可以将其转换为标准的 openssh 格式,如下所示:
ssh-keygen -i -f keyfile.pub > newkeyfile.pub
References
参考
- Source:
http://www.treslervania.com/node/408 - Mirror: https://web.archive.org/web/20120414040727/http://www.treslervania.com/node/408.
- 来源:
http://www.treslervania.com/node/408 - 镜像:https://web.archive.org/web/20120414040727/http: //www.treslervania.com/node/408。
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.
我一直忘记这个,所以我要写在这里。非极客,继续走。
在 Windows 上制作密钥的最常见方法是使用 Putty/Puttygen。Puttygen 提供了一个简洁的实用程序来将 linux 私钥转换为 Putty 格式。但是,没有解决的是,当您使用 puttygen 保存公钥时,它将无法在 linux 服务器上运行。Windows 将一些数据放在不同的区域并添加换行符。
解决方案:当您进入在 puttygen 中创建密钥对的公钥屏幕时,复制公钥并将其粘贴到扩展名为 .pub 的文本文件中。您将节省系统管理员数小时的沮丧阅读此类帖子的时间。
但是,系统管理员,您总是会得到一个不稳定的密钥文件,该文件在身份验证日志中不会抛出任何错误消息,除了没有找到密钥,尝试输入密码;即使其他人的密钥工作正常,并且您已将此密钥发送回用户 15 次。
ssh-keygen -i -f keyfile.pub > newkeyfile.pub
应该将现有的 puttygen 公钥转换为 OpenSSH 格式。
回答by Zac
回答by John Jawed
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.
或者,如果您想从 PuTTY 格式的密钥文件中获取私钥和公钥,您可以puttygen
在 *nix 系统上使用。对于大多数基于 apt 的系统puttygen
来说,它是putty-tools
软件包的一部分。
Outputting a private key from a PuTTY formated keyfile:
从 PuTTY 格式的密钥文件中输出私钥:
$ puttygen keyfile.pem -O private-openssh -o avdev.pvk
$ puttygen keyfile.pem -O private-openssh -o avdev.pvk
For the public key:
对于公钥:
$ puttygen keyfile.pem -L
$ puttygen keyfile.pem -L
回答by Purnendu Singh
sudo apt-get install putty
This will automatically install the puttygen tool.
这将自动安装 puttygen 工具。
Now to convert the PPK file to be used with SSH command execute the following in terminal
现在要转换要与 SSH 命令一起使用的 PPK 文件,请在终端中执行以下操作
puttygen mykey.ppk -O private-openssh -o my-openssh-key
Then, you can connect via SSH with:
然后,您可以通过 SSH 连接:
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
http://www.graphicmist.in/use-your-putty-ppk-file-to-ssh-remote-server-in-ubuntu/#comment-28603
回答by jfreak53
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:
我最近在从适用于 Linux 的 Putty 迁移到适用于 Linux 的 Remmina 时遇到了这个问题。所以我的目录中有很多用于 Putty 的 PPK 文件,.putty
因为我已经使用它 8 年了。为此,我使用了一个简单for
的 bash shell 命令来执行所有文件:
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.
非常快速,切中要害,完成了腻子拥有的所有文件的工作。如果它找到带有密码的密钥,它将停止并首先询问该密钥的密码,然后继续。
回答by Bradley Kreider
It's probably easier to create your keys under linux and use PuTTYgen to convert the keys to PuTTY format.
在 linux 下创建密钥并使用 PuTTYgen 将密钥转换为 PuTTY 格式可能更容易。
回答by kovacsbv
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.
我认为 TCSgrad 试图询问(几年前)是如何让 Linux 像他的 Windows 机器那样运行。也就是说,有一个代理(选美)持有私钥的解密副本,因此密码短语只需要输入一次。然后,ssh 客户端 putty 可以登录到他的公钥被列为“已授权”的机器,而无需密码提示。
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.
与此类似的是,作为 ssh 客户端的Linux有一个持有解密私钥的代理,这样当 TCSgrad 键入“ssh 主机”时,ssh 命令将获取他的私钥,并且不会被提示输入密码。当然,主机必须将公钥保存在 ~/.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).
这个场景的 Linux 模拟是使用 ssh-agent(选美模拟)和 ssh-add(向选美添加私钥的模拟)完成的。
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.
对我有用的方法是使用: $ ssh-agent $SHELL $SHELL 是我需要让代理运行并保持运行的魔术。我在网上的某个地方发现了它,它结束了几个小时的撞墙。
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 .
单独键入 $ ssh-add 将添加(默认情况下) ~/.ssh 中默认身份文件中列出的私钥。
A web article with a lot more details can be found here
可以在此处找到包含更多详细信息的网络文章
回答by Uriy MerkUriy
PPK → OpenSSH RSA with PuttyGen & Docker.
PPK → 带有 PuttyGen 和 Docker 的 OpenSSH RSA。
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