
Tutorial10 min read • Dec 12, 2024
How to SSH to a Linux Server: The Definitive Guide
Master the art of remote server management with this comprehensive guide to SSH, keys, and security best practices.
SD
SolarDevs Team
Technical Leadership
What is SSH?
Secure Shell (SSH) is the standard protocol for securely interacting with remote Linux servers. It encrypts all traffic, ensuring that your passwords and data are safe from prying eyes.
The Basic Command
If you have a username and a password, you connect like this:
ssh username@ip-address
Moving Beyond Passwords: SSH Keys
Passwords are vulnerable to brute-force attacks. The "pro" way to connect is using SSH Key pairs.
1. Generate Your Key
On your local machine, run:
ssh-keygen -t ed25519 -C "your_email@example.com"
This creates a private key (~/.ssh/id_ed25519) and a public key (~/.ssh/id_ed25519.pub).
2. Copy Key to Server
ssh-copy-id username@ip-address
Now you can log in without a password. It's faster and significantly more secure.
Hardening Your Server
Once you're in, you should change some defaults in /etc/ssh/sshd_config:
- Disable Root Login: Set
PermitRootLogin no - Disable Password Auth: Set
PasswordAuthentication no - Change Default Port: Move from 22 to something else (e.g., 2222) to avoid 99% of bot scanners.
Remember to restart the service:
sudo systemctl restart ssh
Professional Tips
- SSH Config File: Save your connections in
~/.ssh/configso you can just typessh myserver. - Mosh: Use Mosh for mobile connections or unstable networks.
- Tmux: Always start a Tmux session so your work persists if the connection drops.
Build your future.
Ready to transform your infrastructure with intelligent AI agents?
Initiate Discovery