SSH connections between multiple servers (Linux)

Source: Internet
Author: User
Tags scp command
* SSH connections between multiple servers

For example, four machines need to communicate with each other without a password.
| ---------- + ------------- |
| Host | IP |
| ---------- + ------------- |
| Server01 | 192.168.0.1 |
| Server02 | 192.168.0.2 |
| Server03 | 192.168.0.3 |
| Server04 | 192.168.0.4 |
| ---------- + ------------- |

** Step 1: generate the respective folders

Server01: # mkdir-P/root/. Ssh; chmod 700/root/. SSH
Server02: # mkdir-P/root/. Ssh; chmod 700/root/. SSH
Server03: # mkdir-P/root/. Ssh; chmod 700/root/. SSH
Server04: # mkdir-P/root/. Ssh; chmod 700/root/. SSH

** Step 2: generate the respective keys

1. Enter the/root/. Ssh/directory and run the following command:
Server01: # ssh-keygen-T RSA
Server02: # ssh-keygen-T RSA
Server03: # ssh-keygen-T RSA
Server04: # ssh-keygen-T RSA

Press enter to generate the corresponding key (Private Key: id_rsa) (Public Key: id_rsa.pub)

 

Server01: # cp id_rsa.pub authorized_keys

Server02: # cp id_rsa.pub authorized_keys

Server03: # cp id_rsa.pub authorized_keys

Server04: # cp id_rsa.pub authorized_keys

 

2. Run the following command on the four servers:
Server01: # ssh-keygen-T rsa1-F/etc/ssh/ssh_host_key-n ""
Server01: # ssh-keygen-T rsa1-F/etc/ssh/ssh_host_rsa_key-n ""
Server01: # ssh-keygen-t dsa-F/etc/ssh/ssh_host_dsa_key-n ""
Server01: #/etc/init. d/ssh restart

** Step 3: add the Public Key (id_rsa.pub) of different servers to your authorized_keys file.

(Note: In the following SCP command, you must manually enter the password to log on)
Server01: # SCP 192.168.0.2:/root/. Ssh/id_rsa.pub/root/
Server01: # Cat/root/id_rsa.pub>/root/. Ssh/authorized_keys

Server01: # SCP 192.168.0.3:/root/. Ssh/id_rsa.pub/root/
Server01: # Cat/root/id_rsa.pub>/root/. Ssh/authorized_keys

Server01: # SCP 192.168.0.4:/root/. Ssh/id_rsa.pub/root/
Server01: # Cat/root/id_rsa.pub>/root/. Ssh/authorized_keys

Now/root/. Ssh/authorized_keys on server01 already contains the public key of four servers.

Server01: # SCP/root/. Ssh/authorized_keys SCP 192.168.0.2:/root/. Ssh/authorized_keys
Server01: # SCP/root/. Ssh/authorized_keys SCP 192.168.0.3:/root/. Ssh/authorized_keys
Server01: # SCP/root/. Ssh/authorized_keys SCP 192.168.0.4:/root/. Ssh/authorized_keys

At this point, there should be no password connection between them.

Engoy it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.