Today, when we set up the hadoop environment configuration, We need to log on via SSH without a password. It took a lot of effort and finally got it done.
First, different Linux operating systems may have slightly different commands. my operating system is Ubuntu, So I recorded what I did.
1. hadoop02 @ ubuntuserver2:/root $ ssh-keygen-t rsa command. When the result is displayed, I press enter until the end,
Generating public/private RSA key pair. <br/> enter file in which to save the key (/home/hadoop02 /. SSH/id_rsa): <br/> enter passphrase (empty for no passphrase): <br/> enter same passphrase again: <br/> your identification has been saved in/home/hadoop02 /. SSH/id_rsa. <br/> your public key has been saved in/home/hadoop02 /. SSH/id_rsa.pub. <br/> the key fingerprint is: <br/> 0f: 7e: 45: 6C: 40: 7c: 9d: 46: C5: 12: 31: 09: 5C: 2c: 4A: AA hadoop02 @ brief tuserver2 <br/> the key's randomart image is: <br/> + -- [RSA 2048] ---- + <br/> | Oo .. ** B. | <br/> | OO + B .. | <br/> | O + O. | <br/> | .. o | <br/> |. s. | <br/> | E. o. | <br/> |. o | <br/> |. | <br/> + --------------- + <br/>
2. hadoop02 @ ubuntuserver2:/root $ cat. Ssh/id_rsa.pub>. Ssh/authorized_keys
Note: there is a space between Cat and. Ssh, and between id_rsa.pub and>.
3. hadoop02 @ ubuntuserver2 :~ $ Cd. SSH
4. hadoop02 @ ubuntuserver2 :~ $ LS-
Authorized_keys id_rsa id_rsa.pub
5. hadoop02 @ ubuntuserver2 :~ /. Ssh $ SSH localhost to check whether there is no password to log on
6. Copy id_rsa.pub in hadoop02 to hadoop01.
Hadoop02 @ ubuntuserver2 :~ /. Ssh $ SCP id_rsa.pub hadoop01@192.168.1.135:/home/hadoop01
Note: The hadoop01@192.168.1.135 must be written like this in the Ubuntu operating system, otherwise an error will occur. This may be different from other Linux operating systems. hadoop01 is your login name, And 192.168.1.135 is an IP address.
In this way, the transfer is successful!
7. hadoop01 @ hadoop-MASTER :~ $ Cat id_rsa.pub>. Ssh/authorized_keys
Note that this is in the/hadoop01 directory. After this is completed, hadoop02 does not need a password to access hadoop01.
8, test: In hadoop02, ssh hadoop01@192.168.1.135 test can control hadoop01 directly!