macos 在 Mac 终端中使用 PPK 文件通过 SSH 连接到远程连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3475069/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:08:17  来源:igfitidea点击:

Use PPK file in Mac Terminal to connect to remote connection over SSH

macossshssh-keysopenssh

提问by Anand

I have been using Putty on Windows XP and used the .ppk file to connect to my Linux servers (several servers).

我一直在 Windows XP 上使用 Putty,并使用 .ppk 文件连接到我的 Linux 服务器(多台服务器)。

On the servers I have the following folder and file ~/.ssh/authorized_keys

在服务器上,我有以下文件夹和文件 ~/.ssh/authorized_keys

I now want to use a Mac to connect via the terminal. I have set up the remote connections to the servers manually and want to know how I can setup using the ppk file or the private/public key within it.

我现在想使用 Mac 通过终端连接。我已经手动设置了到服务器的远程连接,想知道如何使用 ppk 文件或其中的私钥/公钥进行设置。

Please note : I already am using private/public key login from Windows so I do not need to create a new key using keygen, I just want to know how to set up now that I have the keys already. (In other words, I already have the authorized key lists on the server, and the public and private key).

请注意:我已经在使用来自 Windows 的私钥/公钥登录,所以我不需要使用 keygen 创建一个新的密钥,我只是想知道如何设置,因为我已经有了密钥。(换句话说,我已经在服务器上拥有授权密钥列表,以及公钥和私钥)。

回答by Purpletoucan

You can sshdirectly from the Terminal on Mac, but you need to use a .PEMkey rather than the putty.PPKkey. You can use PuttyGen on Windows to convert from .PEMto .PPK, I'm not sure about the other way around though.

您可以ssh直接从 Mac 上的终端,但您需要使用.PEM密钥而不是putty.PPK密钥。您可以在 Windows 上使用 PuttyGen 从 转换.PEM.PPK,但我不确定其他方式。

You can also convert the key using puttyfor Mac via portor brew:

您还可以putty通过port或使用Mac转换密钥brew

sudo port install putty

or

或者

brew install putty

This will also install puttygen. To get puttygento output a .PEMfile:

这也将安装puttygen. 要puttygen输出.PEM文件:

puttygen privatekey.ppk -O private-openssh -o privatekey.pem

Once you have the key, open a terminal window and:

获得密钥后,打开一个终端窗口,然后:

ssh -i privatekey.pem [email protected]

The private key must have tight security settings otherwise SSH complains. Make sure only the user can read the key.

私钥必须具有严格的安全设置,否则 SSH 会报错。确保只有用户可以读取密钥。

chmod go-rw privatekey.pem

回答by rinkesh

Convert PPK to OpenSSh

将 PPK 转换为 OpenSSH

OS X: Install Homebrew, then run

OS X:安装 Homebrew,然后运行

brew install putty

酿造安装腻子

Place your keys in some directory, e.g. your home folder. Now convert the PPK keys to SSH keypairs:cache search

将您的密钥放在某个目录中,例如您的主文件夹。现在将 PPK 密钥转换为 SSH 密钥对:缓存搜索

To generate the private key:

生成私钥:

cd ~

puttygen id_dsa.ppk -O private-openssh -o id_dsa

光盘~

puttygen id_dsa.ppk -O private-openssh -o id_dsa

and to generate the public key:

并生成公钥:

puttygen id_dsa.ppk -O public-openssh -o id_dsa.pub

puttygen id_dsa.ppk -O public-openssh -o id_dsa.pub

Move these keys to ~/.ssh and make sure the permissions are set to private for your private key:

将这些密钥移动到 ~/.ssh 并确保将您的私钥的权限设置为私有:

mkdir -p ~/.ssh
mv -i ~/id_dsa* ~/.ssh
chmod 600 ~/.ssh/id_dsa
chmod 666 ~/.ssh/id_dsa.pub

connect with ssh server

连接ssh服务器

ssh -i ~/.ssh/id_dsa username@servername

Port Forwarding to connect mysql remote server

端口转发连接mysql远程服务器

ssh -i ~/.ssh/id_dsa -L 9001:127.0.0.1:3306 username@serverName

回答by dasfrosty

There is a way to do this without installing putty on your Mac. You can easily convert your existing PPK file to a PEM file using PuTTYgen on Windows.

有一种方法可以做到这一点,而无需在 Mac 上安装腻子。您可以在 Windows 上使用 PuTTYgen 轻松地将现有 PPK 文件转换为 PEM 文件。

Launch PuTTYgen and then load the existing private key file using the Load button. From the "Conversions" menu select "Export OpenSSH key" and save the private key file with the .pem file extension.

启动 PuTTYgen,然后使用加载按钮加载现有的私钥文件。从“转换”菜单中选择“导出 OpenSSH 密钥”并使用 .pem 文件扩展名保存私钥文件。

Copy the PEM file to your Mac and set it to be read-only by your user:

将 PEM 文件复制到您的 Mac 并将其设置为您的用户只读:

chmod 400 <private-key-filename>.pem

Then you should be able to use ssh to connect to your remote server

然后你应该可以使用 ssh 连接到你的远程服务器

ssh -i <private-key-filename>.pem username@hostname