Transferring SSH Keys (`id_rsa` and `id_rsa.pub`) to a New System
Seamoon Pandey
Posted on October 28, 2024
SSH keys are essential for secure communication between computers. If you're migrating to a new system but want to retain your existing SSH keys (id_rsa
and id_rsa.pub
), follow these steps to seamlessly transfer them.
Step 1: Locate Your SSH Keys
First, identify the location of your SSH keys on your old system. Typically, they reside in the ~/.ssh/
directory.
cd ~/.ssh/
ls -al
Step 2: Backup Your Keys
Ensure the safety of your SSH keys by creating a backup. Copy them to a secure location, such as an encrypted USB drive or a trusted cloud storage service.
cp id_rsa id_rsa.pub /path/to/backup/location
Step 3: Transfer the Keys to the New System
Use the scp
(secure copy) command to transfer the SSH keys to your new system.
scp /path/to/backup/location/id_rsa /path/to/backup/location/id_rsa.pub user@new_system_ip:~/.ssh/
Replace user
with your username on the new system and new_system_ip
with the IP address or hostname of your new system.
Step 4: Set Permissions
Ensure that the permissions of your id_rsa
file are secure. Only the owner should have read and write permissions.
chmod 600 ~/.ssh/id_rsa
Step 5: Add Public Key to Authorized Keys
Append the contents of your id_rsa.pub
file to the authorized_keys
file on your new system. This allows you to authenticate using your SSH private key.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Step 6: Test the Connection
Finally, test the SSH connection to your new system to ensure everything is set up correctly.
ssh user@new_system_ip
If successful, you should log in to your new system without being prompted for a password.
Congratulations! You've successfully transferred your SSH keys to your new system, ensuring secure access to your remote servers.
Feel free to customize the instructions further based on your specific environment or requirements!
Posted on October 28, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.