🔑
Networking & Server

SSH Server

Secure remote shell access, key authentication, and file transfer

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

SSH lets you control a remote computer securely, as if you're sitting in front of it.

📥

Step 01

Install OpenSSH Server

(01)Install SSH server

Linux
1# Ubuntu / Debian
2sudo apt-get update
3sudo apt-get install -y openssh-server
4
5# RHEL / CentOS / Fedora
6sudo dnf install -y openssh-server
7
8# Enable and start
9sudo systemctl enable sshd
10sudo systemctl start sshd
⚙️

Step 02

Configure SSH

(01)Harden sshd_config

Linux
1sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
2sudo nano /etc/ssh/sshd_config
3
4# Recommended settings:
5# Port 22
6# PermitRootLogin no
7# PasswordAuthentication yes
8# PubkeyAuthentication yes
9# AllowUsers youruser
10
11sudo systemctl restart sshd
12sudo sshd -t # test config

(02)SSH key pair authentication

Linux
1# On client — generate key
2ssh-keygen -t ed25519 -C "you@example.com"
3
4# Copy public key to server
5ssh-copy-id user@server-ip
6
7# Connect with key
8ssh user@server-ip

(03)Disable password auth (keys only)

Linux
1# In /etc/ssh/sshd_config:
2# PasswordAuthentication no
3# ChallengeResponseAuthentication no
4sudo systemctl restart sshd

Step 03

Verify SSH

(01)Test connection

Linux
1sudo systemctl status sshd
2ssh -v user@localhost
3ss -tlnp | grep :22

Step 04

Manage SSH

(01)SCP and SFTP file transfer

Linux
1# Copy to server
2scp file.txt user@server:/home/user/
3scp -r ./folder user@server:/home/user/
4
5# SFTP session
6sftp user@server
7# put file.txt / get file.txt

(02)SSH agent and tunneling

Linux
1eval "$(ssh-agent -s)"
2ssh-add ~/.ssh/id_ed25519
3
4# Local port forward
5ssh -L 8080:localhost:80 user@server
6
7# Remote port forward
8ssh -R 9090:localhost:3000 user@server
🔧

Step 05

Common Problems

#1Permission denied (publickey)

SSH rejected your login — usually a key or password issue.

Linux
1# Check key permissions (must be 600)
2chmod 600 ~/.ssh/id_ed25519
3chmod 700 ~/.ssh
4
5# Verbose login to see why it failed
6ssh -v user@server-ip
7
8# Force password auth (if enabled on server)
9ssh -o PreferredAuthentications=password user@server-ip

#2Connection refused on port 22

Linux
1# On server — check SSH is running
2sudo systemctl status sshd
3sudo ufw allow 22/tcp
4
5# Test port
6nc -zv server-ip 22