1

我无法从 Windows 7 SSH 到 VMWare Guest CentOS 6.2

我的笔记本电脑上有 Windows 7 64 位操作系统。在上面安装了草莓 Perl 5.16.2。我还安装了 VMWare Player 并在其上运行 CentOS 6.2。

使用我在网上找到的文章,我已经成功地从 PUTTY 无密码地 SSH 到 CentOS 6.2。

我在 CentOS 6.2 上创建了用户 perl514。使用下面的脚本,如果我使用用户名和密码登录,一切正常。但它不适用于我使用 PUTTY 随附的 SSH KEYGEN 工具创建的公钥和私钥。

下面给出的是脚本:

    #!C:\strawberry\perl\bin\perl.exe

    use Modern::Perl;
    use Net::SSH2;


    my $hostname = '192.168.247.128';
    my $username = 'perl514';
    my $password = 'redhat';

    my $ssh2 = Net::SSH2->new();
    say "Connecting to $hostname";

    $ssh2->connect("$hostname") || die "PROBELM - $!";

    #$ssh2->auth_password("$username","$password") || die "Username/Password not #right";#COMMENTED OUT. This Works. Stuff given below does not work.
    $ssh2->auth_publickey ("perl514", "C:\\Users\\winuser\\Documents\\perl\\work\\putty_priv.ppk",
                   "C:\\Users\\winuser\\Documents\\perl\\work\\public.pub") || die "ERROR", $ssh2->error;



    my $chan = $ssh2->channel();
    $chan->blocking(0);
    $chan->exec('ls -la');
    while (<$chan>){ print } 

我收到以下错误:

    Connecting to 192.168.247.128
    ERROR-19LIBSSH2_ERROR_PUBLICKEY_UNVERIFIEDInvalid public key at ssh2.pl line 17.

使用用户名和密码,它可以正常工作。但不是用公钥和私钥。

我很确定我在某个地方出错了。请帮助我。

4

3 回答 3

1

Net::SSH2 expects the key files to be in the OpenSSH format that is different to that used by PuTTY.

You should be able to convert to OpenSSH format using the PuTTY GUI. For instance, see How to convert SSH keypairs generated using PuttyGen(Windows) into key-pairs used by ssh-agent and KeyChain(Linux) .

update:

Detailed conversion steps:

  • Open PuTTY key generator
  • Load the private key into it
  • On the conversions menu, export the private key in OpenSSH format
  • Select and copy with the mouse the public key for OpenSSH from the box under "Public key for pasting into OpenSSH authorized_keys file" and paste it into a new file with the same name as the one you have given to the private key with ".pub" appended.
于 2012-11-26T17:03:24.757 回答
0

我没有在 CentOS vm 上安装 ssh 服务器。安装 ssh 服务器后,它工作了。

yum -y install openssh-server openssh-clients
于 2014-02-05T10:25:29.647 回答
0

很抱歉回答这个问题而不是发表评论,但评论部分不允许我将步骤放在另一个步骤之下。我检查了您的链接,这是我的理解:

    1.Open PuttyGen
    2.Click Load
    3.Load your private key
    4.Go to Conversions->Export OpenSSH and export your private key

我知道上面的步骤是在 Windows Box 上运行的,但是下面的步骤呢?它们要在 CentOS Guest 上运行吗?不确定我是否必须在 CentOS 6.2 来宾操作系统中复制 putty 创建的私钥。另一个问题是 Puttygen 创建的私钥在其中包含私钥和公钥。

     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

我这样做的原因是,一旦这个测试设置工作,我将使用类似的方法登录到一些 NAS 阵列(基于 linux)来运行一些报告。因此,问题。

于 2012-11-27T11:40:36.863 回答