Creating a Password-Free Connection Between Two Servers with Proper Permissions
Setting up a password-free SSH connection between two servers, A and B, enhances security and efficiency. This guide will walk you through establishing a secure, key-based connection, ensuring all permissions are correctly set to 600 for safety.
Step 1: Generate SSH Keys
- On Both Server A and B:
- Run
ssh-keygen
to create a pair of keys:id_rsa
(private) andid_rsa.pub
(public). - Ensure the permissions of these keys are set to 600.
- Run
Step 2: Exchange Public Keys
- On Server A:
- Copy the
id_rsa.pub
of Server A to theauthorized_keys
file of Server B.
- Copy the
- On Server B:
- Similarly, copy the
id_rsa.pub
of Server B to theauthorized_keys
file of Server A.
- Similarly, copy the
Connecting Using Private Key:
- To connect to Server A from B (or vice versa), use the private key (id_rsa) with the following command:
Replacessh user@xxx.xxx.xxx.xxx -i <path-to-private-key>
xxx.xxx.xxx.xxx
with the actual server IP and specify the correct path to your private key.
Additional Tips:
- From any other server (say Server Z with IP zzz.zzz.zzz.zzz), you can use the
ssh-copy-id
command to easily copy your public key to Servers A or B:ssh-copy-id root@
zzz.zzz.zzz.zzz - Reverse the process to allow the opposite connection.
Important Notes:
- Always ensure your keys' permissions are set to 600 to prevent unauthorized access.
- Regularly update and rotate your keys for enhanced security.
By following these steps, you'll establish a secure, password-free connection between two servers, ensuring efficient and safe operations.
No comments:
Post a Comment