SSH (Secure Shell) – Simple Guide

What is SSH?

SSH (Secure Shell) is a secure network protocol used to connect to remote servers and manage them safely over a network.

It allows you to log in, run commands, and transfer files on another machine using encrypted communication.

Why is SSH used?

How SSH Works (Step-by-Step)

1. Client initiates connection

ssh user@server_ip

Your system acts as the SSH client, and the remote machine runs the SSH service (sshd).

2. Server identifies itself

The server sends its host key. The client checks it against the known_hosts file to prevent man-in-the-middle attacks.

3. Key exchange and encryption setup

The client and server agree on encryption algorithms and create a secure encrypted tunnel.

4. User authentication

Authentication can be done using:

5. Secure session established

Once authenticated, a secure shell session is created where all commands and responses are encrypted.

SSH Troubleshooting (Common Issues)

1. Connection timed out

ssh: connect to host x.x.x.x port 22: Connection timed out

Causes: Server down, firewall blocking port 22, wrong IP address.

Fix: Check server status, firewall rules, and IP address.

2. Permission denied

Permission denied (publickey)

Causes: Wrong username, incorrect key, missing public key.

Fix:

chmod 400 key.pem

3. Host key verification failed

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

Fix:

ssh-keygen -R server_ip

4. Too many authentication failures

Fix: Specify the key explicitly.

ssh -i key.pem user@server_ip

5. SSH service not running

systemctl status sshd
systemctl start sshd

Key Points to Remember