Objective
The project needs to write scripts to upload or download files between servers, but there is no relevant server to test the script, so proceed to install two server, and then use the relevant SSH commands to configure the server public key authentication login.
Steps
1. Install two Linux servers under the VM box and use the bridged network type so that the two servers will have their own independent IP
2. On the current server using SSH command to connect to another server, because the public key authentication login is not configured, this is required to enter password to log in
Command: SSH [USER]@[HOSTNAME|IP]
Example: SSH [email protected]
A. The system will prompt you to continue the connection because it is the first connection
B. After you enter Yes, you are prompted for password, and the. SSH directory is automatically created under the current user's home directory, and then the Know_hosts file is created below this directory to store information about the target server
C. After entering password, connect to the target server, you can use the command Ls-al to view the content
D. Use the exit command to disconnect
3. Configure the Public key authentication login, first use the Ssh-keygen command to create the current server's public and private keys
Command: Ssh-keygen
The system will prompt for the key store directory and key name, if you do not want to enter, press ENTER, the system will use the default directory and key name
Default directory and secret key name:/home/ftpiosh/.ssh/id_rsa,/home/ftpiosh/.ssh/id_rsa.pub, a public key and a private key
4. Use the Ssh-copy-id command to copy the current server's public key to the appropriate directory for the target server
Command: Ssh-copy-id [User]@[host Name|ip]
Example: Ssh-copy-id [email protected]
A. The system prompts for a password, enter the password, back to display a key added successfully
B. Target server view public key content
The public key is stored in the/home/ftpiosh/.ssh/authorized_keys file
5. Verify the Public key authentication login
Command: SSH [USER]@[HOSTNAME|IP]
Example: SSH [email protected]
The system will log in directly without the need to enter password
The above is purely a personal point of view, if there is wrong, please correct me!
Configuration of public key authentication mode between SSH servers