用命令ssh-keygen -t rsa在
serverA中生成密钥对,-t rsa表示采用RSA算法来生成密钥对.生成的密钥对默认存放在~/.ssh/目录中,id_rsa.pub中存放公钥,id_rsa存放私钥.
(注:在生成密钥对的时候系统会提示输入密钥对的密码,这里请直接回车,不要输入密码,否则后面打通通道之后仍然需要密码,只不过是用这里设置的密码而已)
将id_rsa.pub中的公钥拷贝出来,追加到 serverB中的~/.ssh/authorized_keys文件中.
本机ssh打通自己:
zj@debian-zj:~/repos$ cd ~
zj@debian-zj:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zj/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zj/.ssh/id_rsa.
Your public key has been saved in /home/zj/.ssh/id_rsa.pub.
The key fingerprint is:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX zj@debian-zj
The key's randomart image is:
+--[ RSA 2048]----+
| xxxxxxxxxx |
| xxxxxxxxxx |
| xxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxx |
|xxxxxxxxxxxx |
|xxxxxx |
|xxxx |
+-----------------+
zj@debian-zj:~$ cd ~/.ssh
zj@debian-zj:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
zj@debian-zj:~/.ssh$ touch authorized_keys
zj@debian-zj:~/.ssh$ cat id_rsa.pub > authorized_keys
test:
zj@debian-zj:~/.ssh$ ssh 127.0.0.1
Linux debian-zj 2.6.26-1-686 #1 SMP Fri Mar 13 18:08:45 UTC 2009 i686
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.
zj@debian-zj:~$ exit
logout
Connection to 127.0.0.1 closed.
zj@debian-zj:~/.ssh$
说明:
authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。
chmod 400 authorized_keys
(注:在生成密钥对的时候系统会提示输入密钥对的密码,这里请直接回车,不要输入密码,否则后面打通通道之后仍然需要密码,只不过是用这里设置的密码而已)
将id_rsa.pub中的公钥拷贝出来,追加到 serverB中的~/.ssh/authorized_keys文件中.
本机ssh打通自己:
zj@debian-zj:~/repos$ cd ~
zj@debian-zj:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zj/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zj/.ssh/id_rsa.
Your public key has been saved in /home/zj/.ssh/id_rsa.pub.
The key fingerprint is:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX zj@debian-zj
The key's randomart image is:
+--[ RSA 2048]----+
| xxxxxxxxxx |
| xxxxxxxxxx |
| xxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxx |
|xxxxxxxxxxxx |
|xxxxxx |
|xxxx |
+-----------------+
zj@debian-zj:~$ cd ~/.ssh
zj@debian-zj:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
zj@debian-zj:~/.ssh$ touch authorized_keys
zj@debian-zj:~/.ssh$ cat id_rsa.pub > authorized_keys
test:
zj@debian-zj:~/.ssh$ ssh 127.0.0.1
Linux debian-zj 2.6.26-1-686 #1 SMP Fri Mar 13 18:08:45 UTC 2009 i686
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.
zj@debian-zj:~$ exit
logout
Connection to 127.0.0.1 closed.
zj@debian-zj:~/.ssh$
说明:
authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。
chmod 400 authorized_keys
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21845741/viewspace-609908/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21845741/viewspace-609908/