Setting up passwordless SSH login with key pairs makes connecting to your servers both quicker and more secure, since you’re no longer typing a password every time or relying on one to keep people out. This guide covers generating a key on your client machine and configuring passwordless logins to two separate servers.
Step 1: Generate a Key Pair on the Client
On the client machine, open a terminal and generate a key. We’re using ed25519 here, which is the modern, secure default:
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_client -C "[email protected]"
Step 2: Copy the Public Key to Each Server
Use ssh-copy-id to install your public key on each server, replacing <username> and the hostname with your own. Run it once for each server:
ssh-copy-id -i ~/.ssh/id_ed25519_client.pub <username>@<server1_hostname>
ssh-copy-id -i ~/.ssh/id_ed25519_client.pub <username>@<server2_hostname>
If ssh-copy-id isn’t available on your system, you can achieve the same thing by manually appending the contents of the .pub file to ~/.ssh/authorized_keys on each server.
Step 3: Configure SSH on the Client
To avoid typing out the full hostname, user, and key path every time, set up a config file on the client that gives each server a short alias:
nano ~/.ssh/config
Add a block for each server, filling in your own hostnames and usernames:
Host server1
HostName <server1_hostname>
User <server1_username>
IdentityFile ~/.ssh/id_ed25519_client
Host server2
HostName <server2_hostname>
User <server2_username>
IdentityFile ~/.ssh/id_ed25519_client
Save and exit.
Step 4: Test the Connection
Thanks to the aliases in your config file, you can now connect to either server by name, with no password prompt:
ssh server1
ssh server2
If both connect straight through without asking for a password, you’re done. From here you’ve got quick, key-based access to both servers, and you can extend the same config with more hosts as your setup grows.


Leave a Reply