SSH β Secure Shell
Generate keys, connect to remote servers, and copy files securely β the daily reality of managing cloud machines.
SSH (Secure Shell) is how DevOps engineers connect to remote servers. Every time you deploy to AWS, configure an Azure VM, or access a Kubernetes node, you use SSH.
π― Learning Objectives
By the end of this lesson you will:
- Understand what SSH is and how it works
- Generate an SSH key pair
- Connect to a remote server
- Simplify connections with an SSH config file
- Copy files securely with SCP
How SSH Works
SSH creates an encrypted tunnel between your machine and a remote server β no password is ever sent in plain text.
Your Laptop (SSH client)
β
Internet (encrypted, port 22)
β
Remote Linux Server (sshd)
β
Your terminal sessionSSH Key Pairs
SSH uses public/private key authentication:
- Private key β stays on your machine. Never share it.
- Public key β goes on the server. Safe to share.
When you connect, the server challenges your client to prove it holds the private key matching the public key on file.
Generate an SSH Key
ssh-keygen -t ed25519 -C "your-email@example.com"Accept the default location and set a passphrase. This creates two files:
~/.ssh/id_ed25519 # private key β never share this
~/.ssh/id_ed25519.pub # public key β copy this to serversConnect to a Remote Server
ssh username@server-ip # basic connection
ssh ubuntu@54.123.45.67 # e.g. Ubuntu on AWS EC2
ssh -i ~/.ssh/my-key.pem ubuntu@54.123.45.67 # using an AWS .pem keyCopy your public key so you can log in without a password:
ssh-copy-id ubuntu@54.123.45.67SSH Config β Stop Typing Long Commands
Instead of retyping addresses, define hosts in ~/.ssh/config:
Host myserver
HostName 54.123.45.67
User ubuntu
IdentityFile ~/.ssh/id_ed25519Now connect with just:
ssh myserverCopy Files Securely with SCP
scp localfile.txt ubuntu@54.123.45.67:/home/ubuntu/ # upload
scp ubuntu@54.123.45.67:/var/log/app.log ./ # download
scp -r ./myfolder ubuntu@54.123.45.67:/home/ubuntu/ # whole folderTroubleshooting
| Problem | Cause | Fix |
|---|---|---|
Permission denied (publickey) |
Wrong key or not copied | ssh-copy-id or check the -i path |
Connection refused |
sshd not running / wrong port |
Confirm the SSH service is running |
Connection timed out |
Firewall blocking port 22 | Check the security group / firewall |
Unprotected private key file |
Key permissions too open | chmod 400 ~/.ssh/id_ed25519 |
β Protect your private key
If SSH refuses to use your key with an βunprotected private keyβ warning, tighten the permissions: chmod 600 ~/.ssh/id_ed25519. A private key readable by others is a security hole.
π§ͺ Hands-on Lab
Generate and Inspect a Key Pair
- Generate a key pair:
ssh-keygen -t ed25519 -C "devops-practice" - View your public key with
cat ~/.ssh/id_ed25519.pub - Fix permissions:
chmod 600 ~/.ssh/id_ed25519 - If you have a cloud VM, connect with
ssh -i ~/.ssh/your-key.pem ubuntu@YOUR-IP
π§ Knowledge Check
Which file should you NEVER share?
What port does SSH use by default?
πΌ Interview Preparation
Why is SSH key authentication preferred over passwords?
π Section Complete
Youβve completed the Linux section of the Ultimate DevOps Learning Hub. You now have a solid foundation in:
- Linux fundamentals and the filesystem
- File permissions and ownership
- Bash scripting
- Networking and connectivity
- SSH remote access
Next, we move into version control β Git and GitHub.