SSH
SSH (Secure Shell) is an encrypted network protocol for remote login and command execution. It authenticates with key pairs or passwords and protects all traffic from eavesdropping, replacing plaintext tools such as Telnet.
Understanding SSH
What Is SSH and Why Is It Used?
SSH is the secure front door to Linux servers. Telnet sent passwords and commands in plain text, so anyone sniffing the network could read them. SSH encrypts the whole session, and it checks the server's identity with host keys, which helps defend against man-in-the-middle attacks.
How an SSH Connection Is Established
The client connects to the server's SSH daemon (sshd, port 22 by default), both sides agree on a session key through a key exchange, the user authenticates, and an encrypted session starts.
Practical SSH Commands
ssh rahul@10.0.1.50ssh -p 2222 rahul@10.0.1.50ssh -i ~/.ssh/id_ed25519 rahul@10.0.1.50ssh -v rahul@10.0.1.50 # debug, use -vvv for moressh rahul@10.0.1.50 'df -h' # run one command scp app.log rahul@10.0.1.50:/tmp/rsync -avz ./deploy/ rahul@10.0.1.50:/opt/app/ ssh -L 5433:localhost:5432 rahul@10.0.1.50 # local port forwardssh -J bastion@52.66.1.100 rahul@10.0.1.50 # jump hostAliases in ~/.ssh/config save typing:
Host mumbai-prod HostName 10.0.1.50 User rahul IdentityFile ~/.ssh/id_ed25519Troubleshooting SSH
| Symptom | Command | What to Check |
|---|---|---|
| Connection refused | ssh -v user@host |
sshd running, port, firewall |
| Permission denied | ssh -v user@host |
Key in authorized_keys, perms |
| Host key changed | ssh-keygen -R host |
Stale known_hosts entry |
| Slow login | ssh -o ConnectTimeout=5 |
DNS lookup delay |
SecurityDisable password login on production servers with
PasswordAuthentication noin/etc/ssh/sshd_config, reload sshd, and use keys. Consider restricting port 22 to known source addresses.
Common MistakeBlindly deleting a changed host key warning. It can mean a rebuilt server, but it can also mean an interception attempt, so verify before you remove the entry.
TipUse
~/.ssh/confighost aliases sossh mumbai-prodpicks the right user, port, and key.
Frequently Asked Questions
What made SSH replace Telnet?
Telnet sends everything, including passwords, as plaintext. SSH encrypts the session and verifies the server identity, closing both the eavesdropping and the impersonation gap.
Why disable password authentication on SSH servers?
Internet-facing SSH is constantly probed by password-guessing bots. Key-only login removes that attack path, especially when combined with fail2ban or a restricted source range.
What does the known_hosts file do?
It stores the host keys of servers you have connected to. If a server's key later changes, SSH warns you, which helps detect man-in-the-middle attacks.