Setting up SSH on a Linux Server
A quick guide on getting SSH up and running securely.
When getting a new Linux server or VM ready for remote access, setting up SSH (Secure Shell) is one of the first tasks. Here’s a quick guide to get you started securely.
The first steps
- Install OpenSSH Server (if not already installed):
# 1. Install OpenSSH Server
sudo apt update
sudo apt install openssh-server
2. Configure SSH
Edit the SSH configuration file to enhance security:
# 2. Edit SSH configuration
sudo nano /etc/ssh/sshd_config
Make the following changes:
- Change the default port (optional but recommended):
Port 2222 - Disable root login:
PermitRootLogin no - Allow only specific users (optional):
AllowUsers your_username - Save and exit the file.
- Restart the SSH service to apply changes:
sudo systemctl restart sshdEnable UFW Firewall
To secure your SSH server, it’s a good idea to set up a firewall using UFW (Uncomplicated Firewall).
# 1. Default deny incoming, allow outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing
# 2. Allow SSH on the new port
sudo ufw allow 2222/tcp
# 3. Enable it
sudo ufw enable
Check status
sudo ufw status numbered
Quick, easy, and essential for a secure lab environment.
Comments