Linux 116: Configuring SSH for Secure Remote Access
Secure Shell (SSH) is the standard method for securely accessing and managing remote Linux servers. Whether you’re administering a personal server or managing cloud infrastructure, configuring SSH properly is essential for security and productivity.
1. What is SSH?
SSH (Secure Shell) is a cryptographic network protocol for operating network services securely over an unsecured network. The most common use is remote login to a Linux server.
- Default port: 22
- Protocol version: SSH-2 (most secure and widely used)
2. Installing the OpenSSH Server
Debian/Ubuntu
RHEL/CentOS/Fedora
Start and enable the SSH service:
3. Basic SSH Usage
Connect to a remote server:
Optional port usage:
4. Securing SSH Access
Change the Default Port
Edit the config file:
Update:
Restart the service:
Disable Root Login
In the same file (sshd_config
), set:
Limit Users
Restrict SSH access to specific users:
5. Using SSH Key Authentication
Generate SSH Keys (on local machine)
Copy Key to Server
Now you can connect without a password:
Disable Password Authentication (server)
Edit sshd_config
:
Restart SSH:
6. Enabling SSH Firewall Rules
Allow SSH with UFW:
7. Useful SSH Features
SSH Tunneling
Forward a local port to a remote server:
SSH Agent Forwarding
Use your local SSH key to authenticate with services on the remote server:
8. Monitoring SSH Login Attempts
Use journalctl
:
Or analyze /var/log/auth.log
or /var/log/secure
depending on your distro:
9. Fail2ban for SSH Brute Force Protection
Install Fail2ban:
Enable and start:
Basic protection for SSH is enabled by default.
10. Conclusion
Proper SSH configuration is essential to secure remote access. By hardening SSH with non-default ports, key authentication, and login restrictions, you significantly reduce the attack surface of your Linux server.
Next Steps:
- Set up 2FA (two-factor authentication) for SSH
- Explore using tools like Mosh for mobile-friendly SSH sessions
- Learn about ProxyJump and SSH config for multi-hop access
Up next: Linux 117: Automating with Ansible for Configuration Management