Tired of typing your server's IP address and username every time you connect?
Instead of running:
ssh username@192.168.1.100
You can simply run:
ssh server-01
Let's set it up! 🚀
1. 🔑 Generate an SSH Key
On your local machine, run:
ssh-keygen -t ed25519
This generates two files:
-
~/.ssh/id_ed25519— Your private key. Keep it secret. -
~/.ssh/id_ed25519.pub— Your public key. This can be shared with your server.
If you already have an SSH key, you can skip this step.
🔒 Security tip: Use a strong passphrase to protect your private key.
2. 📤 Add Your Public Key to the Server
The easiest way is:
ssh-copy-id username@192.168.1.100
Alternatively, append the contents of your public key to the server user's ~/.ssh/authorized_keys file.
To display your public key, run:
cat ~/.ssh/id_ed25519.pub
Copy the output and append it to ~/.ssh/authorized_keys on the server. Make sure the file contains one valid public key per line.
⚠️ Important: Never copy your private key (
id_ed25519) to the server. Only your public key (id_ed25519.pub) belongs there.
3. ⚙️ Configure SSH
Open your local SSH configuration file:
vi ~/.ssh/config
Add the following configuration:
Host server-01
HostName 192.168.1.100
User username
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Replace 192.168.1.100 with your server's IP address or hostname and username with your actual server username.
Here's what each option means:
-
Host— The shortcut name you want to use. -
HostName— The actual server IP address or hostname. -
User— The username used to log in. -
IdentityFile— The private key SSH should use. -
IdentitiesOnly yes— Tells SSH to use the configured identity rather than trying other available identities.
Save the file and exit your editor.
For additional security, ensure your local SSH files have appropriate permissions:
4. 🚀 Connect with One Command!
Now, instead of typing the full connection details, simply run:
ssh server-01
That's it! SSH reads your configuration and fills in the connection details automatically. 🎉
Want to troubleshoot connection issues?
Run:
ssh -v server-01
The verbose output helps you diagnose connection problems and authentication failures.
5. 🛡️ A Few Security Checks
Convenience should never come at the cost of security.
✅ Check Server File Permissions
On the server, ensure the SSH directory and authorized_keys file are owned by the correct user and have appropriate permissions.
Common settings are:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
🔍 Verify the Server's Identity
The first time you connect, SSH may ask you to trust the server's host key.
Verify its fingerprint through a trusted channel before accepting it. This helps protect you from connecting to an impersonated server.
🔐 Consider Disabling Password Authentication
If you administer the server, consider disabling SSH password authentication after confirming that key-based login works and you have a recovery method.
Important: Keep an existing session open while testing a new connection to avoid locking yourself out.
🚫 Never Share Your Private Key
Your private key is like the key to your house. Anyone who obtains it may be able to access servers that trust it.
If your private key is compromised:
- Remove the corresponding public key from affected servers.
- Generate a new key pair.
- Install the new public key on your servers.
- Update any SSH configurations that reference the old key.
💡 Bonus: Manage Multiple Servers
You can add multiple server aliases to your ~/.ssh/config file:
Host server-01
HostName 192.168.1.100
User username
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host production
HostName prod.example.com
User deploy
IdentityFile ~/.ssh/production_key
IdentitiesOnly yes
Host staging
HostName staging.example.com
User deploy
IdentityFile ~/.ssh/staging_key
IdentitiesOnly yes
Now you can connect to different servers with simple commands:
ssh server-01
ssh production
ssh staging
No more memorizing IP addresses or repeatedly typing usernames!
🎯 Final Thoughts
SSH keys handle authentication, while ~/.ssh/config stores your connection details.
Together, they make server access simpler without repeatedly typing the same information.
One command. Less repetition. Better security. 🔐

Top comments (0)