[hadoop@weekend110 ~]$ ssh-keygen -t rsa 用来生产密钥对 Generating public/private rsa key pair. Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): Enter passphrase (empty for no passphrase): 不要输入密码 Enter same passphrase again: Your identification has been saved in /home/hadoop/.ssh/id_rsa. Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub. The key fingerprint is: 7b:4a:0d:85:42:ec:b6:0c:14:88:d9:c6:c1:f8:46:90 hadoop@weekend110 The key's randomart image is: +--[ RSA 2048]----+ |.X.o.o. | |E B ... . | | + . .. . . | | o . o. . | | . + .S | | o + | | o o | | . o | | . | +-----------------+ [hadoop@weekend110 ~]$ ll -a 密钥文件为隐藏 需要加-a total 275760 drwx------. 20 hadoop hadoop 4096 Oct 22 20:11 . drwxr-xr-x. 3 root root 4096 Mar 5 2014 .. drwxrwxr-x. 4 hadoop hadoop 4096 Oct 21 18:53 app -rw-------. 1 hadoop hadoop 684 Oct 21 18:51 .bash_history -rw-r--r--. 1 hadoop hadoop 18 Feb 21 2013 .bash_logout -rw-r--r--. 1 hadoop hadoop 176 Feb 21 2013 .bash_profile -rw-r--r--. 1 hadoop hadoop 124 Feb 21 2013 .bashrc drwxr-xr-x. 2 hadoop hadoop 4096 Oct 9 21:18 .cache drwxr-xr-x. 4 hadoop hadoop 4096 Oct 9 21:18 .config drwx------. 3 hadoop hadoop 4096 Oct 9 21:18 .dbus -rw-------. 1 hadoop hadoop 16 Oct 9 21:18 .esd_auth drwx------. 4 hadoop hadoop 4096 Oct 21 07:22 .gconf drwx------. 2 hadoop hadoop 4096 Oct 21 07:50 .gconfd drwxr-xr-x. 6 hadoop hadoop 4096 Oct 9 21:46 .gnome2 drwx------. 2 hadoop hadoop 4096 Oct 9 21:46 .gnome2_private drwxrwxr-x. 3 hadoop hadoop 4096 Oct 9 21:18 .gnote drwx------. 2 hadoop hadoop 4096 Oct 21 07:22 .gnupg drwxrwxr-x. 2 hadoop hadoop 4096 Oct 9 21:19 .gstreamer-0.10 -rw-rw-r--. 1 hadoop hadoop 142 Oct 21 07:22 .gtk-bookmarks drwx------. 2 hadoop hadoop 4096 Oct 9 21:18 .gvfs -rw-rw-r--. 1 hadoop hadoop 138656756 Oct 4 14:21 hadoop-2.4.1.tar.gz -rw-------. 1 hadoop hadoop 1240 Oct 21 07:22 .ICEauthority -rw-r--r--. 1 hadoop hadoop 143588167 Oct 21 21:02 jdk-7u65-linux-i586.tar.gz drwxr-xr-x. 3 hadoop hadoop 4096 Oct 9 21:18 .local drwxr-xr-x. 5 hadoop hadoop 4096 Oct 9 21:46 .mozilla drwxr-xr-x. 2 hadoop hadoop 4096 Oct 9 21:18 .nautilus drwx------. 2 hadoop hadoop 4096 Oct 9 21:18 .pulse -rw-------. 1 hadoop hadoop 256 Oct 9 21:18 .pulse-cookie drwx------. 2 hadoop hadoop 4096 Oct 22 22:15 .ssh drwxr-xr-x. 2 hadoop hadoop 4096 Oct 9 21:18 Templates -rw-------. 1 hadoop hadoop 5203 Oct 22 20:11 .viminfo -rw-------. 1 hadoop hadoop 794 Oct 21 07:28 .xsession-errors -rw-------. 1 hadoop hadoop 820 Oct 21 07:17 .xsession-errors.old [hadoop@weekend110 ~]$ cd .ssh 进入密钥文件 [hadoop@weekend110 .ssh]$ ll total 12 -rw-------. 1 hadoop hadoop 1671 Oct 22 22:15 id_rsa 私钥 -rw-r--r--. 1 hadoop hadoop 399 Oct 22 22:15 id_rsa.pub 公钥 -rw-r--r--. 1 hadoop hadoop 1186 Oct 21 20:21 known_hosts [hadoop@weekend110 .ssh]$ scp id_rsa.pub spark01:/home/hadoop 将密钥传到spark01机器,因为这里模拟,并没有次主机,错误正常 ssh: Could not resolve hostname spark01: Name or service not known lost connection [hadoop@weekend110 .ssh]$
此后在spark01配置 ,进入.SHH文件。第一次是没有authorized_key这个文件夹,用touch创建,创建之后将权限改为-rw-------即可。然后将公钥追加到此文件即可。 [hadoop@spark01 .ssh]$ cat ../id_rsa.pub >>./authorited_key 前面的../id_rsa.pub 代表的是前一个主机传过来的公钥,不是spark01中ssh文件里的id_rsa.pub 结束。