Skip to main content

Command Palette

Search for a command to run...

How to Use a Single SSH Key Across Multiple Devices (Laptop & Office PC)

Updated
3 min read
How to Use a Single SSH Key Across Multiple Devices (Laptop & Office PC)
T
Team Lead building scalable backend systems and DevOps pipelines. Experienced in AWS, Laravel, and automation workflows. I write about real-world engineering problems and solutions.

Do you switch between a laptop and an office PC frequently and need to SSH into the same servers? Setting up a single SSH key across both systems can simplify your workflow and avoid generating and managing multiple keys.

In this article, I’ll walk you through how to securely share an SSH key between two devices — the right way.


Why Use a Single SSH Key?

Using a single key pair:

  • Reduces management overhead

  • Keeps your identity consistent across devices

  • Makes adding new servers easy (just share one public key)


Step 1: Generate an SSH Key

On either your laptop or office PC, generate a new key pair:

ssh-keygen -t rsa -b 4096 -C "your-email@example.com" -f ~/.ssh/trushang_dev

Or, for a modern and faster alternative:

ssh-keygen -t ed25519 -C "your-email@example.com" -f ~/.ssh/trushang_dev

This creates:

  • ~/.ssh/trushang_dev (private key)

  • ~/.ssh/trushang_dev.pub (public key)

Press Enter to skip the passphrase or set a secure one.


Step 2: Securely Copy the Private Key to Your Second Device

On the machine where the key was generated:

scp ~/.ssh/trushang_dev user@second-device:/home/user/.ssh/

Then on the second device:

chmod 600 ~/.ssh/trushang_dev

⚠️ Security Note: Never share your private key over email or chat. Always use encrypted channels or offline methods (like a USB drive).


Step 3: Share the Public Key With IT

On either machine, run:

cat ~/.ssh/trushang_dev.pub

Copy the output and share it with your IT or DevOps team. They will add it to the ~/.ssh/authorized_keys file on the server(s) you need access to.


Step 4: Add the SSH Key to Your SSH Agent

Start the SSH agent and add your key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/trushang_dev

If this fails with an agent error, ensure the agent is running or use tools like keychain for persistent sessions.


Create or edit the SSH config file:

nano ~/.ssh/config

Add the following:

Host my-dev-server
  HostName your.server.ip
  User your-username
  IdentityFile ~/.ssh/trushang_dev
  IdentitiesOnly yes
  StrictHostKeyChecking yes

Now, instead of typing the full SSH command each time, simply run:

ssh my-dev-server

Step 6: Test the SSH Connection

Try connecting from both devices:

ssh -i ~/.ssh/trushang_dev your-username@your.server.ip

Or, if you used a config alias:

ssh my-dev-server

Reusing the Key for Future Projects

Want access to a new server? Just send the public key:

cat ~/.ssh/trushang_dev.pub

That's it — no need to generate new keys each time.


DevOps Pro Tips

  • Use ed25519 instead of RSA for better performance and smaller key size

  • Always set correct permissions (chmod 600) on private keys

  • Rotate keys yearly or after suspected compromise

  • Backup your SSH key in a secure vault (Bitwarden, 1Password)

  • Avoid copying the private key via email or chat — never do this!


Conclusion

With a shared SSH key, you’ll save time and streamline access across your systems. Just remember to treat your private key like a password — protect it and never share it in insecure ways.

Have questions or tips for managing SSH keys more securely? Drop them in the comments!