← Back to Home
πŸ”‘

SSH β€” Secure Shell

Generate keys, connect to remote servers, and copy files securely β€” the daily reality of managing cloud machines.

⏱13 min readπŸ“šDevOps Fundamentals

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:


How SSH Works

SSH creates an encrypted tunnel between your machine and a remote server β€” no password is ever sent in plain text.

text
Your Laptop  (SSH client)
 ↓
Internet    (encrypted, port 22)
 ↓
Remote Linux Server  (sshd)
 ↓
Your terminal session

SSH Key Pairs

SSH uses public/private key authentication:

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

bash
ssh-keygen -t ed25519 -C "your-email@example.com"

Accept the default location and set a passphrase. This creates two files:

text
~/.ssh/id_ed25519        # private key β€” never share this
~/.ssh/id_ed25519.pub    # public key β€” copy this to servers
bash β€” 80Γ—24
student@devops:~$cat ~/.ssh/id_ed25519.pub

Connect to a Remote Server

bash
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 key

Copy your public key so you can log in without a password:

bash
ssh-copy-id ubuntu@54.123.45.67

SSH Config β€” Stop Typing Long Commands

Instead of retyping addresses, define hosts in ~/.ssh/config:

text
Host myserver
  HostName 54.123.45.67
  User ubuntu
  IdentityFile ~/.ssh/id_ed25519

Now connect with just:

bash
ssh myserver

Copy Files Securely with SCP

bash
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 folder

Troubleshooting

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

  1. Generate a key pair: ssh-keygen -t ed25519 -C "devops-practice"
  2. View your public key with cat ~/.ssh/id_ed25519.pub
  3. Fix permissions: chmod 600 ~/.ssh/id_ed25519
  4. If you have a cloud VM, connect with ssh -i ~/.ssh/your-key.pem ubuntu@YOUR-IP

🧠 Knowledge Check

Knowledge Check

Which file should you NEVER share?

Knowledge Check

What port does SSH use by default?


πŸ’Ό Interview Preparation

Interview Q&A

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:

Next, we move into version control β€” Git and GitHub.

Up Next

Introduction to Git & GitHub

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lesson→