M30A - SSH Foundation
SSH Foundation
Master the Secure Shell (SSH) protocol to securely connect to remote servers, and implement key-based authentication to eliminate passwords.
- Master the Secure Shell (SSH) protocol to securely connect to remote servers, and implement key-based authentication to eliminate passwords.
Teleportation
Everything you have learned so far assumed you were sitting directly in front of the computer. In the real world, the servers you manage are in data centers hundreds or thousands of miles away.
You must securely project your terminal across the internet.
The industry standard tool for this is SSH (Secure Shell). It creates an encrypted tunnel between your laptop and the remote server. Anyone listening on the internet only sees scrambled mathematical noise.
(Note: Windows 10/11 now includes the OpenSSH client natively, so the commands are identical on both platforms!)
1. The Basic Connection
To connect, you need the remote server’s IP address (or domain name) and the username you want to log in as.
ssh [username]@[IP_Address]
ssh admin@192.168.1.100
You can also use domain names
When you connect for the very first time, your computer will ask: Are you sure you want to continue connecting (yes/no)? It is recording the server’s unique fingerprint to ensure you aren’t being tricked by a hacker next time. Type yes.
You will then be asked for the user’s password.
💀 The Password Danger
If you put a Linux server on the internet with a weak password, a botnet will guess the password via brute-force in less than 48 hours. Human passwords are fundamentally insecure for remote server administration.
2. Cryptographic Keys (No More Passwords)
Expert operators do not use passwords to log into servers. They use Key Pairs.
A Key Pair consists of two mathematically linked files:
- The Private Key: A massive, unguessable string of characters that stays securely on your laptop. Never share this with anyone.
- The Public Key: A string you can safely give to the world (or put on a server).
When you try to log in, the server issues a mathematical challenge that can only be solved if you possess the Private Key. It is un-hackable by modern brute-force techniques.
Step 1: Generate the Keys
Run this on your local laptop:
Generate a modern, secure ED25519 key
ssh-keygen -t ed25519 -C “your_email@example.com”
Press Enter to save it to the default location (~/.ssh/id_ed25519)
Optional: It will ask for a passphrase to encrypt the key itself.
Step 2: Push the Public Key to the Server
Now, you must copy the .pub file to the remote server, placing it in a specific hidden folder (~/.ssh/authorized_keys).
Windows PowerShell doesn’t have an automated tool for this. You have to push it manually or use bash via WSL.
Read your public key, send it over SSH, and append it to the file on the server
Get-Content ~/.ssh/id_ed25519.pub | ssh user@192.168.1.100 “cat >> ~/.ssh/authorized_keys”
Linux has a brilliant automated script.
ssh-copy-id user@192.168.1.100
It will ask for the password one last time.
Step 3: Log In Instantly
Type ssh user@192.168.1.100 again. You will be logged in instantly without typing a password. You have achieved cryptographic authentication.
3. The SSH Config File (Shortcuts)
If you manage 10 different servers, typing ssh production-user-service-account@10.25.100.41 -p 2255 -i ~/.ssh/special_key every day is exhausting.
You can save all of these settings in a configuration file on your laptop.
Open (or create) the file ~/.ssh/config using a text editor (Notepad, nano, VS Code).
# ~/.ssh/config contents
Host web-prod
HostName 10.25.100.41
User production-user-service-account
Port 2255
IdentityFile ~/.ssh/special_key
Host home-pi
HostName 192.168.1.50
User pi
Now, to log into that massive production server, you just type:
ssh web-prod
What You Just Learned
ssh user@IPprojects your terminal onto a remote computer.- Passwords on the internet are dangerous.
ssh-keygencreates an un-hackable Private and Public key pair.ssh-copy-idcopies the secure Public key to the remote server.- The
~/.ssh/configfile acts as your address book, storing complex usernames, custom ports, and specific keys behind simple shortcut names.
You can now connect to servers anywhere in the world. Next, we look at how those servers locate each other using DNS.