DEV Community

Yousuf Basir
Yousuf Basir

Posted on

Managing Multiple SSH Servers Across Windows & macOS with SSH Config & Tmux

If you work with multiple servers — some requiring .pem keypairs and others with password authentication — you know how quickly it becomes messy. Add in the fact that you might switch between Windows at home and macOS at work, and suddenly managing SSH connections can feel like juggling knives.

In this article, I’ll show you how to organize your SSH access across both Windows and macOS using:

  • OpenSSH (built-in on both OS)
  • ~/.ssh/config (for managing profiles)
  • Multiplexing (to speed up connections)
  • tmux (to keep sessions alive even if your laptop disconnects)

Let’s dive in 👇


1. Install OpenSSH

  • macOS → Already installed, just open Terminal.
  • Windows 10/11 → OpenSSH is included, but if missing:
 Settings → Apps → Optional Features → Add a Feature → OpenSSH Client 
Enter fullscreen mode Exit fullscreen mode

Now you can run:

ssh user@server-ip 
Enter fullscreen mode Exit fullscreen mode

2. Use ~/.ssh/config for Profiles

Instead of typing long commands, store servers in a config file:

  • Windows pathC:\Users\<YourUser>\.ssh\config
  • macOS/Linux path~/.ssh/config

Example:

# Server with PEM key Host project-server HostName 203.0.113.10 User ubuntu IdentityFile ~/.ssh/project-server.pem # Server with password login Host db-server HostName 198.51.100.20 User root PreferredAuthentications password # GitHub shortcut Host github.com User git IdentityFile ~/.ssh/github_id_rsa 
Enter fullscreen mode Exit fullscreen mode

Now you can connect with simple commands:

ssh project-server ssh db-server 
Enter fullscreen mode Exit fullscreen mode

3. Handling Password Servers

Configs don’t store passwords for security reasons. Options:

  • On macOS/Linux:
 brew install hudochenkov/sshpass/sshpass sshpass -p 'mypassword' ssh db-server 
Enter fullscreen mode Exit fullscreen mode
  • Or better: set up key-based login:
 ssh-copy-id user@db-server 
Enter fullscreen mode Exit fullscreen mode

(Now you won’t need the password every time 🚀)


4. Speed Up Connections with Multiplexing

Add this to your ~/.ssh/config:

Host * ControlMaster auto ControlPath ~/.ssh/cm-%r@%h:%p ControlPersist 10m 
Enter fullscreen mode Exit fullscreen mode

✅ First connection = normal login
✅ Next connections (within 10 mins) = instant, no re-auth


5. Keep Sessions Alive with tmux

On any server, install tmux:

sudo apt install tmux # Ubuntu/Debian brew install tmux # macOS 
Enter fullscreen mode Exit fullscreen mode

Usage:

tmux new -s mysession # start session Ctrl+b d # detach but keep running tmux attach -t mysession # reattach later 
Enter fullscreen mode Exit fullscreen mode

Now your scripts and processes survive even if your laptop disconnects.


6. Sync Configs Between Machines

To keep everything consistent across Windows and macOS:

  • Store ~/.ssh/config and .pem files in a private Git repo or encrypted cloud storage.
  • Copy or symlink them into ~/.ssh on each machine.

✅ Final Thoughts

By combining:

  • SSH config for organizing servers,
  • Multiplexing for faster connections, and
  • tmux for persistent sessions,

…you get a portable, reliable, and cross-platform SSH workflow that works seamlessly on Windows and macOS.

No more remembering IPs, juggling .pem files, or retyping passwords. Just:

ssh project-server 
Enter fullscreen mode Exit fullscreen mode

And you’re in! 🎉


💬 What about you? Do you use a GUI-based SSH manager (like Termius or MobaXterm), or do you prefer CLI setups like this one?

Top comments (0)