First, the preparatory work
1) is connected to the server with the client tools linux (ssh client or putty). Enter the command in root user
vi / etc / hosts, edit the hosts file in vi, as follows:
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 #::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.160 hadoop01 192.168.1.161 hadoop02 192.168.1.162 hadoop03 192.168.1.163 hadoop04 192.168.1.164 hadoop05
2) Enter the command: cd .ssh into the directory rsa public and private key files are stored, delete id_rsa, id_rsa.pub files in the directory.
Second, to generate new rsa public and private key file on each machine, and copied to a unified authorized_keys file
1) Log hadoop01, enter the command in the .ssh directory:
ssh-keygen -t rsa
After three carriage returns, the directory will have id_rsa, id_rsa.pub file. Other hosts also produced key file to use in this manner.
2) Log hadoop01, enter the command:
cat id_rsa.pub >> authorized_keys
It will copy the contents of the public key id_rsa.pub to authorized_keys file.
3) sign in to other hosts, other hosts public key file contents are copied to the authorized_keys file on the hadoop01 host, the command is as follows:
ssh-copy-id -i hadoop01 # log hadoop02, copied to the public key in authorized_keys hadoop01 ssh-copy-id -i hadoop01 # log hadoop03, copied to the public key in authorized_keys hadoop01 ssh-copy-id -i hadoop01 # Log hadoop04, copy the public key to the authorized_keys hadoop01 in ssh-copy-id -i hadoop01 # login hadoop05, copy the public key to authorized_keys hadoop01, the final authorized_keys document reads as follows:
[root@hadoop01 .ssh]# more authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp7jp4a1/deK4B/eZW8kdiCQvzpKe4Id0uP0DdONFW85r 20rpH4ZpNSB7JNYFiqjMUPQ/2EWLXh7xoa9UntKsMVVcZr3BTiXRZ0Gx7IDacwz8Cq0qYrwUCMTKt7QF xK5RwXyuZqDFjc2yC3/ZoqeyeLERFTll3ZLGeFsXhJjlkPTvtnvx0zX6lacPZL4VguoM5YHw3KaJg8bd qehJzbQoPS8sm00ES4iygbR+Ixz1cnGTrtNU1S3lh4/y0PC6spMs9Z2Mf097FTLQJXJDiGqU9Tq3MHvl srZFx92H4y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wvl80bdF9YvYEtg ymHO4/tANKWSNKGw2EcthNWyQiN4hIYOoBQaUA3FlAXyqcD2+Q+2frf0gNF5KfKKLXmmlAuS9Oi6JqFJ f1BLmMquI4n02owzU0zlkj3Px5IcCfQbDQ/JedHcjxEKP2S+9m3yxG4h2Q== root@hadoop05 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyS1PbXTgFqHcGV/k0QUZni5xB5+q71qx4r5xto+WLkVQ MiS3gR/VYZoyDLrQRVf5t0JiliCgHeU0MG/ASd1LPbsVYCX5V9cmcm1hMByDKJ6FwIxz5cY4y1dBpwAZ 2E24CQWfZuevaeIFnL80RGGLhRgCxbLb3aPvRZuV34utD+5kgAFJwYCQYN4KnFG1S5e4X6U5J3FsCDby GD7dhtWWktMV2SAnWjrmULguaVRqO0sDIEiVSc9+KKqAmlOab+5SbZAI5+3hzJog5c3i4f5fHXWnxYqy LNo3yYSWraV5KcYIlNPqX6iJKvjLWbNDwD3+70u4nWjBSXXufhff71LdHw== root@hadoop01
Third, the authorization authorized_keys file
1) Log hadoop01, enter the command in the .ssh directory:
chmod 600 authorized_keys
, The effect is as follows:
[root@hadoop01 .ssh]# ls -al total 28 drwx------. 2 root root 4096 Oct 24 12:27 . dr-xr-x---. 22 root root 4096 Oct 24 19:20 .. -rw-------. 1 root root 1975 Oct 24 12:27 authorized_keys -rw-------. 1 root root 1975 Oct 24 12:09 authorized_keys_20141024 -rw-------. 1 root root 1675 Oct 24 12:23 id_rsa -rw-r--r--. 1 root root 395 Oct 24 12:23 id_rsa.pub -rw-r--r--. 1 root root 2020 Oct 24 12:10 known_hosts
Fourth, to assign authorization to other files on the host
1) Log hadoop01, copy the license file hadoop02, hadoop03 ..., the command is as follows:
scp /root/.ssh/authorized_keys hadoop02: /root/.ssh/ # copied to hadoop02 SCP /root/.ssh/authorized_keys hadoop03: # /root/.ssh/ copied to hadoop03 SCP /root/.ssh/authorized_keys hadoop04: /root/.ssh/ # copied to hadoop04 SCP /root/.ssh/authorized_keys hadoop05: # /root/.ssh/ copied to hadoop05
2) At this point, free password has been set up, pay attention to the first ssh password is required for login, you can access the password-free login again.