准备3台虚拟机
-
hadoop01 192.168.88.131
-
hadoop02 192.168.88.132
-
hadoop03 192.168.88.133
ssh基本用法
ssh加另一台主机IP
免密登录原理
实现方法
配置主机与IP地址的映射
[root@hadoop01 .ssh]# vim /etc/hosts
添加下列代码
192.168.88.131 hadoop01 192.168.88.132 hadoop02 192.168.88.133 hadoop03
每个节点生成ssh密钥
[root@hadoop01 ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): 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: 86:28:2e:e1:91:91:97:57:12:9c:47:4c:e9:bb:32:cf root@hadoop01 The key's randomart image is: +--[ RSA 2048]----+ | .o*+. | | . .oo+ | | o o .o | | + .. o | |.o. . . S | |.o.. o | |... . | | . o.. | | +E | +-----------------+ [root@hadoop01 ~]# cd .ssh [root@hadoop01 .ssh]# ll 总用量 12 -rw-------. 1 root root 1675 6月 13 01:14 id_rsa -rw-r--r--. 1 root root 395 6月 13 01:14 id_rsa.pub
-
-rw-------. 1 root root 1675 6月 13 01:14 id_rsa //私钥文件
-
-rw-r--r--. 1 root root 395 6月 13 01:14 id_rsa.pub //公钥文件
-
-rw-r--r--. 1 root root 396 6月 13 01:05 known_hosts //记录连接过的计算机公钥信息**
复制SSH密钥到目标主机,开启无密码SSH登录
[root@hadoop01 ~]# ssh-copy-id hadoop01 The authenticity of host 'hadoop01 (192.168.88.131)' can't be established. RSA key fingerprint is db:b1:63:46:ea:f0:d4:57:d7:55:45:ce:d1:61:bd:d4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'hadoop01,192.168.88.131' (RSA) to the list of known hosts. root@hadoop01's password: Now try logging into the machine, with "ssh 'hadoop01'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [root@hadoop01 ~]# ssh-copy-id hadoop02 ...... [root@hadoop01 ~]# ssh-copy-id hadoop03 ......
这样在hadoop01主机就可以免密登录hadoop02、hadoop03主机了,但在hadoop02和hadoop03上还不能免密登录。因此还要在hadoop02和hadoop03上执行该操作。