Setup Passwordless SSH in Linux
Setup Passwordless SSH Between node1 and node2 in Linux
Setting up Passwordless SSH enables secure authentication between Linux servers without requiring a password for every login. It is an essential configuration for PostgreSQL replication, high availability (HA), automated backups, failover management, and routine Linux administration.
In this guide, we’ll configure passwordless SSH between two Linux servers named node1 and node2 for the root user.
Note: The same process can be followed for any Linux user by replacing the root account with the required username.
Environment
| Server Name | IP Address |
|---|---|
| node1 | 192.168.1.181 |
| node2 | 192.168.1.182 |
Step 1: Verify Existing SSH Keys
Before generating new SSH keys, verify whether keys already exist.
Generating new keys unnecessarily may break existing passwordless SSH configurations.
On node1
ls -al ~/.ssh/id_*.pub
On node2
ls -al ~/.ssh/id_*.pub
If output appears similar to:
/root/.ssh/id_rsa.pub
then SSH keys already exist.
Skip to Step 3.
Otherwise continue to generate new SSH keys.
Step 2: Generate SSH Keys
Run the following command on both servers.
On node1
ssh-keygen
When prompted:
Enter file in which to save the key (/root/.ssh/id_rsa):
Press Enter
Enter passphrase (empty for no passphrase):
Press Enter
Enter same passphrase again:
Press Enter
Expected output:
Your identification has been saved in:
/root/.ssh/id_rsa
Your public key has been saved in:
/root/.ssh/id_rsa.pub
On node2
ssh-keygen
Again press Enter for every prompt.
Expected output:
Your identification has been saved in:
/root/.ssh/id_rsa
Your public key has been saved in:
/root/.ssh/id_rsa.pub
Step 3: View Public SSH Keys
Display the public key on each server.
On node1
cat ~/.ssh/id_rsa.pub
Copy the entire output.
On node2
cat ~/.ssh/id_rsa.pub
Copy the entire output.
Your public keys will look similar to:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC3cZea310BBpCqZbmhjoCb1IbmqSQvnEYwcqK+11n23ulR10Z16H4Rf3mj7aaFVRJiOtxWXQ0n3xFZgjsF4/W9QvjcgByA8DRm5IAkxdn3IAshVFqMJtgTkLox644tk00D3AX1SUY/pbKO5BpqaAqyCLnge+cTsMqyKTBWXqSQwPIDUalIlFZUvvfEHTNl0tpLOqmV+YE6kQNiw5tveOOTWdi2Lz2l/efbxXN7sgu53Au/ABZ4tdlZqUpVipNoE5WE1u+KdS8CpEl57ECtGyJvYuqc/KE9S/B2HfLrpPwjmTiCppAQK2HElYDwv7SV8snhV+WyEHM+WKISao9cGW3t5U18YzrKnhI0OEYD6ZF90bBwqbm/HRN7tAJTF74ueZ7iD7GHXX6kWYQ4WPcQ+dfmlmSuA232LBRCSetkjOssLd3SsTqS6FXN3aGG66O5fTTPBLVKfSoOkptMiHmGRXaLvDcPGOCiGwCLPRAe/okmOArYdJIru7HUHOzVng5gy3A3L3jpw0Kg9/M4xDOkrgqbYwJN8qNLLF8tQdLcPXY0aTnu2tk6AwlBASPRmIhoyblmJHVA+uV97W+rRE34fIiq1qXy87zJZ55tlA14liCprDr8kHmWtkCaeK5lcW4imKaxH4raEFeJjdPi4BLsDUlmTNH0JZVJjHQ2u8GDO3BOyQ== [email protected] ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6tidiCRszVpoXPVAK8Kfk7xNBRa8KPf57fWQH1rsOpXzhMOinZFfZTa+CG9tXpgGSBA/JQqF6wWOUyFsiQGomgauxy6G/pKUOzSebHhEsF38ElJjlP8m4ahk8IQg4DNo55/3zsYvqKJwv7nn5YeDguscEV6BtI0kngLpfp9zhpSlnt0QBjGg7JhuZAHToGJfP0ZVbBfPZOMavkZ0r3Bpg/uenZ8K6dh4EOP21P0QYcS8YxPlodWzqVnkGlHwnNLgvcQwUl81xQYPlzLZgguHYPH6HsXI5cXfEs2pF0XeNNabLoKi01fB98gcm3XHqxA/TKXAOnO1TTqi3sRpAD1n5 [email protected]
Step 4: Add Public Keys to authorized_keys
Each server must trust the other server.
This is done by placing both public keys inside the authorized_keys file.
On node1
vi ~/.ssh/authorized_keys
Paste:
- node1 public key
- node2 public key
Save the file.
On node2
vi ~/.ssh/authorized_keys
Paste:
- node1 public key
- node2 public key
Save the file.
Step 5: Set Proper Permissions
SSH is very strict about permissions.
Run the following commands on both servers.
On node1
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
On node2
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Step 6: Test Passwordless SSH
Connect from node1 to node2
Run:
ssh root@node2
or
The first time you connect, you’ll see:
The authenticity of host 'node2' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)?
Type:
yes
You should now log in without being asked for the root password.
Connect from node2 to node1
Run:
ssh root@node1
or
Again, type:
yes
for the first connection.
You should now be able to log in without entering the password.
Verify Passwordless SSH
To confirm everything is working correctly:
From node1
ssh root@node2 hostname
Expected output:
node2
From node2
ssh root@node1 hostname
Expected output:
node1
If the hostname is displayed without prompting for a password, the passwordless SSH configuration is successful.
Common Troubleshooting Tips
If passwordless SSH does not work:
-
Verify SSH keys exist:
ls ~/.ssh -
Check permissions:
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys -
Ensure the SSH service is running:
systemctl status sshd -
Restart the SSH service if required:
systemctl restart sshd - Confirm that both public keys are correctly added to the
authorized_keysfile. - Verify that hostname resolution or IP connectivity between node1 and node2 is working.
Conclusion
Passwordless SSH is an essential Linux administration skill and is widely used in environments such as Oracle RAC, DevOps automation, Ansible, Kubernetes, and cloud infrastructure. By exchanging SSH public keys between node1 and node2, administrators can securely log in without repeatedly entering passwords, making automation and remote management significantly more efficient.





