How to Set Up Password‑Free SSH Login Between Two Linux Hosts

Learn step‑by‑step how to configure passwordless SSH from a user on one Linux host to another by generating RSA keys, copying the public key, creating the necessary .ssh directory, and troubleshooting common permission issues.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Set Up Password‑Free SSH Login Between Two Linux Hosts

Assume you are the user "aliceA" on hostA and you want to SSH to hostB as user "aliceB" without typing a password.

First, log in to hostA as aliceA.

Generate an RSA key pair (the keys are stored in ~/.ssh). $ ssh-keygen -t rsa Create the .ssh directory on hostB for aliceB (skip this step if it already exists). $ ssh aliceB@hostB mkdir -p .ssh Copy aliceA's public key to aliceB's authorized_keys on hostB.

$ cat .ssh/id_rsa.pub | ssh aliceB@hostB 'cat >> .ssh/authorized_keys'

After this, ssh from aliceA@hostA to aliceB@hostB will no longer prompt for a password. The whole process can also be done in one step with ssh-copy-id -i ~/.ssh/id_rsa.pub aliceB@hostB.

Troubleshooting

If you are still asked for a password after key authentication is set up, check the system logs (e.g., /var/log/secure ) for errors such as: Authentication refused: bad ownership or modes for file /home/aliceB/.ssh/authorized_keys This usually means the authorized_keys file has incorrect permissions or ownership. Ensure the file is not readable by anyone other than its owner.

$ chmod 700 ~/.ssh/authorized_keys
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

System AdministrationSSHpasswordless loginPublic Key Authentication
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.