主机1:172.16.222.88 [root@localhost ~]
主机2:172.16.198.23 root@kali64:~#
[root@localhost ~]# ssh-keygen -t rsa ===》在主机1上操作,生成密钥文件
Generating public/private rsa key pair.
Enter file in which to save the key(/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y ====è覆盖原来的文件,如果是第一次则不会出现这个
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/root/.ssh/id_rsa.
Your public key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
35:8a:19:96:f5:1a:80:04:25:04:e0:66:48:fe:bc:2croot@localhost.localdomain
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
|++++o.. . |
|= .. + . |
|.= + . + |
|o o . + = . |
| o o S |
| .. |
| E o |
| . |
| |
+-----------------+
[root@localhost ~]#
scp /root/.ssh/id_rsa.pub root@172.16.198.23:/root/.ssh/authorized_keys
=======》在主机1上操作,将生成的公钥上传到主机2上,并且重命名。
root@172.16.198.23'spassword: ====》输入主机2的密码将公钥上传
id_rsa.pub
100% 408 0.4KB/s 00:00
[root@localhost ~]# ssh172.16.198.23 =====》在主机1上通过ssh登录主机2
Linux kali64 3.18.0-kali3-amd64#1 SMP Debian 3.18.6-1~kali2 (2015-03-02)x86_64
The programs included with the KaliGNU/Linux system are free software;
the exact distribution terms for eachprogram are described in the
individual files in /usr/share/doc/*/copyright.
Kali GNU/Linux comes with ABSOLUTELY NOWARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jul 14 22:45:24 2015 from172.16.222.88
root@kali64:~# =====》可以看到无需输入密码即可登录。
若是想让主机2免输入密码登录主机1,依此进行
转载于:https://blog.51cto.com/6207455/1674801