Home › Other › SSH

SSH

SSH is the standard way to get a secure shell on a remote machine. Learn the command, then switch to keys.

SSH (Secure Shell) gives you an encrypted connection to another computer’s command line. It is how almost everyone administers servers. The traffic is encrypted end to end, so it is safe even over untrusted networks.

Connecting

ssh [email protected]
ssh [email protected] -p 2222   # non-default port

The first time, SSH shows the server’s fingerprint and asks you to confirm. It remembers it in ~/.ssh/known_hosts, and warns you loudly if it ever changes — which could mean the server was rebuilt, or something is impersonating it.

Keys instead of passwords

Password logins are brute-forceable. A key pair is far stronger and more convenient. You generate two linked keys — a private one you keep, a public one you hand out:

$ ssh-keygen -t ed25519
# creates ~/.ssh/id_ed25519 (private) and id_ed25519.pub (public)

$ ssh-copy-id ada@server      # install your public key there

Now you log in with no password, and the private key never leaves your machine. Protect it with a passphrase, and let ssh-agent hold it unlocked during your session.

Copying files

scp file.txt ada@server:/home/ada/     # copy up
scp ada@server:/var/log/app.log .      # copy down
rsync -av ./site/ ada@server:/var/www/  # sync a folder

Config shortcuts

Put common hosts in ~/.ssh/config so you can type ssh web instead of the full address:

Host web
  HostName 203.0.113.10
  User ada
  Port 2222
Hardening a server: once key login works, disable password authentication entirely in /etc/ssh/sshd_config (PasswordAuthentication no) to shut the door on brute-force attempts.

Keep reading