Putty-ssh自动登陆

作者:聂勇 欢迎转载,请保留作者信息并说明文章来源!

生成密钥 | Generating SSH Keys

1、Linux主机生成密钥

1
ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/nieyong/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/nieyong/.ssh/id_rsa.
Your public key has been saved in /home/nieyong/.ssh/id_rsa.pub.
The key fingerprint is:
8f:91:be:f9:5b:29:a6:61:7e:dc:2e:d1:e2:5b:0d:98 nieyong@nieyong-redhat

在目录 /home/nieyong/.ssh/ 生成两个密钥文件:

  • id_rsa.pub (公钥)
  • id_rsa (私钥)

2、修改公钥名称

1
mv id_rsa.pub authorized_keys

3、将私钥 id_rsa 复制到客户端。

4、使用puttygen.exe转换格式:

1)打开puttygen.exe –> Conversions –> Import Key
导入私钥

2)选择服务器复制下来的私钥文件id_rsa

3)点击按钮”Save private key” -> develop-redhat64bit-nieyong-private.ppk (保存转换格式后私钥)
转换私钥

设置Putty | Setting

1、设置Putty。

1)在左侧菜单栏选择:Connection –> Data,在Auto-login username后的输入框中输入自动登录的用户名。
设置自动登陆的用户名

2)Connection –> SSH –> Auth,点击Private key file for authentication下面输入框后面的”Browse…”按钮,选择私钥develop-redhat64bit-nieyong-private.ppk。
设置授权的私钥

2、点击”Open”按钮登录后显示:

Using username “nieyong”.
Authenticating with public key “develop-redhat64bit-nieyong-private”
Last login: Fri Sep 14 10:15:25 2012 from 192.168.56.101

注:用puttygen生成的密钥,openssh不能识别,在登录时会提示”server refused our key”。