git ssh 密钥密码在 Windows 中有效,但在 linux 中无效

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

ssh key passphrase works in windows but not in linux

gitsshpassphrase

提问by Jepessen

I'm working to a project in git. In Windows, I'm using git extensions to manage this project, and to access to the public repository they gave me a .ppk key. I load it into git extension, with the passphrase that they gave me, and it works.

我正在用 git 做一个项目。在 Windows 中,我使用 git 扩展来管理这个项目,并访问公共存储库,他们给了我一个 .ppk 密钥。我使用他们给我的密码将它加载到 git 扩展中,并且它工作正常。

Now I set a linux (ubuntu-32bit) virtual machine, and I want to access also from this machine to the repository.

现在我设置了一个 linux (ubuntu-32bit) 虚拟机,我也想从这台机器访问存储库。

From another thread that I've seen in this site, I use, to clone the repository, the following command:

从我在本站点中看到的另一个线程中,我使用以下命令来克隆存储库:

ssh-agent bash -c 'ssh-add /home/myHome/mykey.ppk; git clone git@serveraddress:project.git'

Then, the shell tells me to insert the passphrase

然后,外壳告诉我插入密码

Enter passphrase for /home/myHome/mykey.ppk:

But when I insert it, it tells me that's a bad passphrase. I've checked it a lot of times, and I'm sure that I use the same passphrase that I use in windows. So how can I use correctly the key in Linux?

但是当我插入它时,它告诉我这是一个错误的密码。我已经检查了很多次,而且我确定我使用的密码与我在 Windows 中使用的密码相同。那么如何在 Linux 中正确使用密钥呢?

Thanks in advance for your replies.

提前感谢您的回复。

回答by lunaryorn

The Linux SSH client (typically OpenSSH) can't read the PPK format used by the Windows SSH client Putty. You need to convert the "PPK" key given to you into an OpenSSH key first. Install "putty" on Linux and use the puttygencommand line tool:

Linux SSH 客户端(通常是 OpenSSH)无法读取 Windows SSH 客户端 Putty 使用的 PPK 格式。您需要先将提供给您的“PPK”密钥转换为 OpenSSH 密钥。在 Linux 上安装“putty”并使用puttygen命令行工具:

$ sudo aptitude install putty
$ mkdir -p ~/.ssh
$ puttygen ~/mykey.ppk -o ~/.ssh/id_rsa -O private-openssh

Enter your passphrase, and you'll get an OpenSSH-compatible key in the standard location ~/.ssh/id_rsa. Afterwards you can just use ssh-add(without any arguments!) to add this key to the SSH agent.

输入您的密码,您将在标准位置获得一个与 OpenSSH 兼容的密钥~/.ssh/id_rsa。之后您可以使用ssh-add(不带任何参数!)将此密钥添加到 SSH 代理。

Alternatively you can use the PUTTYgen program provided by putty on Windows.

或者,您可以在 Windows 上使用 putty 提供的 PUTTYgen 程序。