SSH Basics
Connect to remote servers securely with SSH, keys, and the config file for easy access.
What you'll learn
- What SSH is and why it is more secure than passwords
- Generating and using SSH key pairs
- Connecting to remote servers and copying files
- Configuring the SSH config file for shortcuts
Concept
What Is SSH?
SSH (Secure Shell) is a cryptographic network protocol for accessing remote computers securely over an unsecured network. It encrypts all traffic between your machine and the server, preventing eavesdropping and man-in-the-middle attacks. SSH is the primary way DevOps engineers connect to Linux servers, deploy code, and administer remote systems. It replaces older, insecure protocols like Telnet and FTP.
SSH Key Pairs
SSH uses public-key cryptography. You generate a key pair: a private key (which you keep secret) and a public key (which you share). You copy the public key to the server's ~/.ssh/authorized_keys file. When you connect, the server verifies you possess the matching private key without ever transmitting it. This is far more secure than passwords — keys cannot be brute-forced and are never sent over the network.
Connecting and Copying Files
To connect, use ssh user@hostname. To copy files, use scp for single files or rsync for directories with efficient delta transfers. The ssh-keygen command generates keys, and ssh-copy-id installs your public key on a server. Once set up, you can connect and transfer files without typing a password each time.
The SSH Config File
The ~/.ssh/config file lets you define shortcuts for your servers. Instead of typing ssh -i ~/.ssh/mykey.pem admin@10.0.0.5 -p 2222, you can create a config entry named prod and simply type ssh prod. This file also lets you set default keys, ports, and other options per host, making it much easier to manage multiple servers.
SSH Agent and Forwarding
The SSH agent holds your decrypted private keys in memory so you don't type the passphrase every time. Start it with eval $(ssh-agent) and add keys with ssh-add. Agent forwarding (-A flag) lets you jump from one server to another without copying your private key — the server forwards authentication requests back to your local agent. This is useful for deploying from a CI server to production. However, use forwarding carefully on untrusted servers, as a compromised server could hijack your agent connection.
Example
# Generate an SSH key pair (ED25519 is recommended)
ssh-keygen -t ed25519 -C "you@example.com" -f ~/.ssh/id_ed25519
# Copy your public key to a remote server
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com
# Connect to a remote server
ssh user@server.example.com
# Copy files securely
scp ./app.tar.gz user@server:/tmp/
rsync -avz ./dist/ user@server:/var/www/html/
# SSH config shortcut (~/.ssh/config)
# Host prod
# HostName 10.0.0.5
# User admin
# IdentityFile ~/.ssh/id_ed25519
# Port 2222
ssh-keygen creates a key pair, ssh-copy-id installs the public key on a server, and scp/rsync transfer files. The SSH config file defines connection shortcuts.
Try it
- SSH Key Generator
Generate SSH key pairs in your browser.
- PEM Parser
Parse and inspect PEM certificate files.
- Password Generator
Generate strong passwords for SSH access.
Common mistakes
The mistake
Using RSA keys with small bit sizes
The fix
Use ED25519 keys (ssh-keygen -t ed25519) or RSA with at least 4096 bits. Older 1024-bit RSA keys are considered insecure and can be cracked.
The mistake
Leaving private key permissions too open
The fix
Set chmod 600 ~/.ssh/id_ed25519. SSH will refuse to use a private key that is readable by other users, as it is a security risk.
Practice SSH Basics
1 exercise
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.