Simplifying SSH
July 01, 2025
How to SSH into a Linux Machine from macOS Without Typing Everything Every Time
If you're tired of repeatedly typing ssh user@host
and entering your password every time you connect to a Linux machine from macOS, there's a much better and more secure way to streamline your workflow.
This guide will walk you through setting up SSH key-based authentication and using an SSH config file for effortless connections.
✅ Step 1: Generate an SSH Key (If You Don’t Already Have One)
First, check if an SSH key already exists:
ls ~/.ssh/id_rsa.pub
If it doesn't, generate a new one:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Press Enter
to accept the default location and file name when prompted.
✅ Step 2: Copy Your SSH Key to the Linux Host
Option A: Using ssh-copy-id
(Recommended)
ssh-copy-id user@host
This will append your public key to the ~/.ssh/authorized_keys
file on the remote Linux machine and set proper permissions.
Option B: Manual Copy (If ssh-copy-id
is not available)
cat ~/.ssh/id_rsa.pub | ssh user@host 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'
After this, you should be able to log in without a password:
ssh user@host
✅ Step 3: Create an SSH Config Entry
To avoid typing the full ssh user@host
every time, create a short alias using the SSH config file.
Edit or create ~/.ssh/config
:
nano ~/.ssh/config
Add the following block:
Host myserver
HostName your.remote.host
User your_user
IdentityFile ~/.ssh/id_rsa
Now you can connect with a simple command:
ssh myserver
✅ Bonus: Integrate with macOS Keychain
If you use a passphrase with your SSH key, macOS can remember it securely in your Keychain.
Extend your SSH config entry:
Host myserver
HostName your.remote.host
User your_user
IdentityFile ~/.ssh/id_rsa
AddKeysToAgent yes
UseKeychain yes
Then add the key to your Keychain:
ssh-add --apple-use-keychain ~/.ssh/id_rsa
✅ Optional: Use a Modern SSH Key Algorithm
RSA is still widely used, but you can opt for a more modern and secure algorithm like Ed25519:
ssh-keygen -t ed25519 -C "[email protected]"
If you do this, make sure to update your SSH config to point to the new key (e.g., ~/.ssh/id_ed25519
).
🧠 Summary
By using SSH keys and the ~/.ssh/config
file, you can streamline your SSH workflow and connect to remote Linux machines quickly and securely.
Benefits
- 🔒 More secure than using passwords
- 🚀 Faster login experience
- 💼 Easily manage multiple SSH connections with aliases
- 🍎 Seamlessly integrates with macOS Keychain