How to Move SSH Keys to Another Computer
In this article
Yes, you can move SSH keys from one computer to another by securely copying your private and public key files to the new system and placing them in the correct directory. This allows you to maintain access to remote servers, Git repositories, and other services without regenerating keys or reconfiguring authentication. Before starting, ensure you know the location of your existing SSH keys and have access to both the source and destination computers.
What You'll Need
- Access to the source computer (where the SSH keys currently reside)
- Access to the destination computer (where you want to move the keys)
- A secure method to transfer files (e.g., USB drive, SCP, SFTP, or encrypted cloud storage)
- Basic familiarity with the command line on both systems
- Optional: password manager or secure notes app if your private key is passphrase-protected
Step-by-Step
- Locate your SSH keys on the source computer. By default, they are stored in the
~/.ssh/directory. Common key file names includeid_rsa(private key),id_rsa.pub(public key),id_ed25519, or others depending on key type. Use the commandls -la ~/.ssh/to list them. - Verify which keys are active by checking if they are referenced in your SSH config file (
~/.ssh/config) or used in known services like GitHub or GitLab. If unsure, assume all keys in~/.ssh/are important. - Copy both the private and public key files you wish to transfer. For example, if using RSA keys, copy
id_rsaandid_rsa.pub. Never share the private key over insecure channels. - Transfer the key files securely to the destination computer. Recommended methods include:
- Using
scp:scp ~/.ssh/id_rsa ~/.ssh/id_rsa.pub user@destination-host:~/.ssh/ - Using a USB drive encrypted with a password
- Using an end-to-end encrypted cloud service (e.g., with client-side encryption enabled)
- Using
- On the destination computer, ensure the
~/.ssh/directory exists. If not, create it withmkdir -p ~/.ssh. - Move the transferred key files into
~/.ssh/if they are not already there. - Set correct permissions on the key files. SSH is strict about file security. Run:
chmod 700 ~/.sshchmod 600 ~/.ssh/id_rsa(or your private key file)chmod 644 ~/.ssh/id_rsa.pub(or your public key file)
- Add the private key to the SSH agent so it’s available for authentication. Start the agent if it’s not running:
eval $(ssh-agent), then runssh-add ~/.ssh/id_rsa. - Test the key by connecting to a service that accepts it, such as a remote server or GitHub:
ssh -T git@github.com. If configured correctly, you’ll see a success message. - Optionally, update your SSH config file (
~/.ssh/config) on the new machine to define host-specific settings, such as custom ports or identity files.
Common Mistakes
- Transferring keys over unencrypted or public channels (e.g., email, unencrypted USB)
- Forgetting to set proper file permissions, which causes SSH to reject the keys
- Only copying the public key and not the private key, which renders authentication impossible
- Overwriting existing keys on the destination without backup, risking access loss
- Using
sudoto run SSH commands unnecessarily, which changes file ownership and causes permission issues
Tips
- Always back up your original keys before moving or modifying them
- Use
ssh-add -lto list loaded keys and confirm your transferred key is active - Consider using a passphrase for your private key to add an extra layer of security
- If you have multiple keys, use the
IdentityFiledirective in~/.ssh/configto specify which key to use for which host - After moving, delete key copies from temporary locations like USB drives or downloads folders
Troubleshooting
If SSH key authentication fails after moving, start with these checks:
- Verify file permissions: private keys must be
600,~/.sshmust be700. Incorrect permissions are the most common cause. - Ensure the private key file is not corrupted during transfer. Compare file sizes or use
md5sumorshasumon both ends. - Check that the SSH agent is running and has loaded the key:
ssh-add -l. If not, add it manually. - Confirm the public key is still registered on the remote server or service (e.g., in GitHub’s SSH settings).
- Test connection in verbose mode:
ssh -v user@host. This reveals whether the key is being offered and accepted. - If you get a "Too many authentication failures" error, SSH may be trying too many keys. Use
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_rsa user@hostto specify only one key. - If the destination is a different user or system, ensure the home directory and
~/.sshare owned by the correct user.
Frequently Asked Questions
Can I use the same SSH key on multiple computers?
Yes, you can copy and use the same SSH private key on multiple computers, but this increases the risk if one machine is compromised. Consider using separate keys per device for better security.
Is it safe to copy SSH keys between computers?
Yes, as long as you use secure transfer methods and protect the private key. Never send private keys over unencrypted email or store them in plain text on shared devices.
Do I need to regenerate SSH keys after moving them?
No, moving keys preserves their functionality. Regeneration is only needed if the key is lost, corrupted, or compromised.
What happens if I lose my private key?
You will lose access to services that require it. Always keep a secure backup and ensure the public key is still accepted on remote systems.
Can I move only the public key?
No. The public key alone cannot authenticate you. You must have the private key on the destination computer for SSH to work.
Should I change the key passphrase after moving?
Not required, but if you suspect the key was exposed during transfer, regenerate it or change the passphrase using ssh-keygen -p.