How to Copy SSH Keys to Another Machine
Introduction
Using SSH keys is the most secure and convenient way to log in to another machine. Instead of typing your password every time, you can authenticate using a public/private key pair. This guide explains how to copy your public key to a remote machine so that passwordless login works reliably.
1. Verify Your SSH Key Pair
On your local machine, your keys are in the .ssh directory:
You should see:
-
id_rsa→ private key (keep secret) -
id_rsa.pub→ public key (this is what we copy to the remote machine)
If you don’t have a key pair, generate one:
2. Copy Your Public Key to the Remote Machine
Option A: Using ssh-copy-id (Recommended)
-
Automatically copies your public key to the remote machine’s
~/.ssh/authorized_keys -
Sets correct permissions
Test login:
You should log in without entering a password.
Option B: Manual Copy
-
Display your public key:
2. Create the .ssh directory and authorized_keys file:
3. Append your public key to authorized_keys:
Test login again:
3. Permissions & Best Practices
-
.sshdirectory →700 -
authorized_keys→600(or644if needed) -
Never copy your private key to another machine
-
Use modern key types like
ed25519for better security
Conclusion
Copying your SSH public key to another machine allows secure, passwordless logins. The simplest method is ssh-copy-id, which handles everything automatically. If needed, you can do it manually by creating .ssh/authorized_keys and appending your public key. Proper permissions are crucial to ensure the key works and remains secure.