🔐 SSH & SCP Basics (Beginner Friendly Guide)

📌 What You’ll Learn

  • What is SSH
  • How to connect to a server
  • What is SCP
  • How to transfer files securely
  • SSH key login (no password)

🧠 1. What is SSH?

SSH (Secure Shell) is used to: - Connect to a remote computer (server) - Run commands from your own terminal

👉 You can control another machine from anywhere


🧩 Easy Analogy (Must Understand)

  • Your computer = 🧑‍💻 You
  • Server = 🏠 Another house
  • SSH = 📞 Secure phone call

👉 You sit at home and control another house remotely


⚙️ 2. Install SSH (If Needed)

🐧 Linux (Ubuntu/Debian)

sudo apt update
sudo apt install openssh-client

🪟 Windows

  • Use PowerShell / CMD
  • Or install Git Bash

🔗 3. Connect to Server

ssh username@server_ip

✅ Example:

ssh ubuntu@192.168.1.10

📌 First time: - Type yes - Enter password


🔑 4. SSH Key Login (No Password)

🧠 What is it?

Instead of typing password every time, you use a key system


🧩 Easy Analogy

  • Public Key = 🔓 Lock you give to server
  • Private Key = 🔒 Key you keep

👉 If both match → access granted


🪄 Step 1: Generate Key

ssh-keygen

👉 Press Enter for all steps


📤 Step 2: Copy Key to Server

ssh-copy-id username@server_ip

✅ Example:

ssh-copy-id ubuntu@192.168.1.10

🔓 Step 3: Login Without Password

ssh username@server_ip

🎉 Now no password needed


📂 5. What is SCP?

SCP (Secure Copy) is used to: - Transfer files between your computer and server - Uses SSH (secure 🔒)


🧩 Easy Analogy

  • SSH = Talking to someone 📞
  • SCP = Sending files 📦

📤 6. Send File to Server

scp file.txt username@server_ip:/path

✅ Example:

scp test.txt ubuntu@192.168.1.10:/home/ubuntu/

📥 7. Download File from Server

Basic command:

scp username@server_ip:/path/to/file .

✅ Example:

scp ubuntu@192.168.1.10:/home/ubuntu/test.txt .

🔑 Using Private Key (Important for VPS/Cloud)

If your server uses a private key (like AWS / OCI), use -i:

scp -i private.key username@server_ip:/path/to/file .

✅ Example:

scp -i mykey.pem ubuntu@192.168.1.10:/home/ubuntu/test.txt .

🧩 Easy Analogy

  • Normal login = Password 🔑
  • Key login = Special access card 🎫

👉 Some servers only allow key-based entry, no password


📁 8. Transfer Folder

scp -r folder_name username@server_ip:/path

⚡ 9. Useful Tips

Custom port:

scp -P 2222 file.txt user@ip:/path

Use key:

ssh -i key.pem user@ip

🚨 10. Common Errors

❌ Permission denied
👉 Check username or key

❌ Connection refused
👉 Server not running or wrong IP


🎯 Conclusion

  • SSH = Remote control 🔌
  • SCP = Secure file transfer 📦
  • Use SSH keys for better security 🔐