SSH Fundamentals: Secure Remote Access and Administration
Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.
Securing Remote Access with SSH
Remote server administration is a daily task for every cybersecurity professional. SSH is the tool that makes it possible — and secure. Whether you are connecting to a compromised host during an incident, managing a firewall remotely, or tunneling traffic through an encrypted channel, SSH is your gateway. This guide walks through SSH setup, key-based authentication, and practical usage patterns.
Prerequisites
Basic Linux command line knowledge. Understanding of IP addresses and ports.
How SSH Works
The SSH Handshake
Basic SSH Usage
ssh user@192.168.1.100 # Basic connection
ssh -p 2222 user@example.com # Non-default port
ssh user@host "ls -la /var/log" # Run single command
ssh -i ~/.ssh/id_rsa user@host # Use specific identity file
SSH Config File (~/.ssh/config)
Host webserver
HostName 192.168.1.100
User admin
Port 22
IdentityFile ~/.ssh/webserver_key
Now connect with: ssh webserver
Key-Based Authentication
Generating Keys
ssh-keygen -t ed25519 -C "email@example.com" # Recommended
ssh-keygen -t rsa -b 4096 -C "email@example.com" # Fallback
Copying Public Key
ssh-copy-id user@192.168.1.100
# Manual:
cat ~/.ssh/id_ed25519.pub | ssh user@host "cat >> ~/.ssh/authorized_keys"
Key Types
| Type | Security | Speed | Recommendation |
|---|---|---|---|
| Ed25519 | Excellent | Fastest | Default choice |
| RSA 4096 | Excellent | Slower | Good fallback |
| DSA | Weak | Moderate | Avoid |
SSH File Transfer
# SCP
scp file.txt user@host:/path/ # Copy to server
scp -r dir/ user@host:/path/ # Copy directory
scp user@host:/var/log/syslog ./ # Copy from server
scp -P 2222 file.txt user@host:/tmp/ # Custom port
# SFTP (interactive)
sftp user@host
# Commands: ls, lls, get, put, rm, mkdir, exit
SSH Tunneling
Local Port Forwarding
ssh -L 8080:internal-server:80 user@gateway
# Access http://localhost:8080 to reach internal web server
Remote Port Forwarding
ssh -R 9000:localhost:3000 user@public-server
# Exposes local port 3000 on remote server's port 9000
Dynamic Port Forwarding (SOCKS Proxy)
ssh -D 1080 user@proxy-server
# Configure browser to use SOCKS5 at localhost:1080
Security Hardening
In /etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Port 2222
AllowUsers admin john
ClientAliveInterval 300
MaxAuthTries 3
LogLevel VERBOSE
sudo systemctl restart sshd
Real-World Examples
Jump Host: ssh -J bastion.example.com internal-server.local
Reverse Tunnel: Device behind NAT: ssh -R 2222:localhost:22 user@public-server then ssh -p 2222 localhost from public server.
SSH as VPN: Dynamic port forwarding encrypts browsing like a VPN.
Common Mistakes
Exposing SSH on default port (22 gets constant probes). Leaving password auth enabled. Sharing private keys. Not using ssh-agent for passphrases.
Best Practices
Use Ed25519 keys. Use an SSH agent. Implement fail2ban. Keep SSH updated. Use jump hosts for private networks. Disable SSH protocol 1.
Related Tools
Mosh — Mobile shell for high latency. autossh — Auto-restart tunnels. sshfs — Mount remote directories. fail2ban — Block brute force. ssh-audit — Test SSH config.
Related Articles
Summary
SSH provides encrypted remote access, file transfer (SCP/SFTP), and tunneling (local/remote/dynamic port forwarding). Best practices include Ed25519 keys, disabling password auth, changing the default port, and using jump hosts for private network access.
Knowledge Check
Frequently Asked Questions
Continue Learning
Linux Package Management: APT, DPKG, and Beyond
Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.
Linux · BeginnerLinux Process Management: Monitoring and Controlling Processes
Learn to manage Linux processes effectively including monitoring tools, signals, priority control, background jobs, and automation with systemd.
Linux · IntermediateLinux Terminal Guide: Advanced Shell Skills for Professionals
Advanced Linux terminal techniques including shell customization, multiplexing, productivity tools, and scripting best practices.
Linux · BeginnerBash Scripting Basics: Automate Tasks Like a Pro
Learn Bash scripting from scratch covering variables, conditionals, loops, functions, error handling, and practical automation scripts for cybersecurity.
Related Security Tools
Hydra
Hydra is a parallelized login cracker that supports numerous protocols including FTP, HTTP, HTTPS, SMB, SSH, and many more. It performs rapid dictionary attacks against login pages and services to test password strength.
Sniffing & SpoofingNetcat
Learn how to use Netcat (nc) in Kali Linux to open a TCP or UDP connection, check a port, and see what a service sends back. Follow the examples to send your first message, inspect HTTP and SMTP responses, and transfer a test file without exposing sensitive data.
Information GatheringNmap
Learn how to use Nmap, the free open-source network scanner: run your first port scan, discover live hosts, detect services and operating systems, and check for vulnerabilities with NSE scripts — a beginner tutorial for Kali Linux.
Maintaining AccessWireGuard
WireGuard is an extremely fast, modern VPN protocol that lives inside the Linux kernel and uses state-of-the-art cryptography — Curve25519 key exchange, ChaCha20Poly1305 encryption, and the Noise protocol framework — in a core codebase of only a few thousand lines. In penetration testing and red team work it creates secure, persistent tunnels for pivoting into internal networks and maintaining encrypted access, while system administrators use the same tool for site-to-site links and road-warrior VPNs. Every peer is identified by a single public key, traffic is bound to that key by cryptokey routing (AllowedIPs), and the protocol stays completely silent toward unauthenticated packets, which makes a WireGuard port nearly invisible to scanners.