Securing SSH, Setting Hostname and Enabling Network Services

Securing SSH involves changing the default SSH port, implementing strong authentication methods, and disabling root login. Setting a hostname helps with system identification and network organization. Enabling network services such as firewalls and intrusion detection systems provides comprehensive security coverage. These practices significantly enhance SSH server security and reduce vulnerability to unauthorized access attempts.

SSH Security Configuration

SSH security begins with modifying the default configuration. The primary steps include changing the default port from 22 to a non-standard port, implementing key-based authentication, and restricting user access.

Step 1: Install OpenSSH Server

sudo apt-get update
sudo apt-get install openssh-server

Step 2: Configure SSH Settings

Edit the SSH configuration file located at /etc/ssh/sshd_config:

sudo nano /etc/ssh/sshd_config

Make the following key modifications:

# Change default port
Port 2222

# Disable root login
PermitRootLogin no

# Enable key-based authentication only
PasswordAuthentication no
PubkeyAuthentication yes

# Allow specific users only
AllowUsers alice bob admin

# Limit login attempts
MaxAuthTries 3

Step 3: Generate SSH Key Pairs

Create SSH keys for secure authentication:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id -p 2222 username@server_ip

Hostname Configuration

Setting a meaningful hostname helps identify systems in network environments:

# Set hostname temporarily
sudo hostname webserver-01

# Set hostname permanently
sudo hostnamectl set-hostname webserver-01

# Verify hostname change
hostnamectl status

Firewall and Network Services

Configure firewall rules to allow only necessary connections:

# Enable UFW firewall
sudo ufw enable

# Allow SSH on custom port
sudo ufw allow 2222/tcp

# Allow specific IP addresses only
sudo ufw allow from 192.168.1.100 to any port 2222

# Check firewall status
sudo ufw status

Enable Additional Security Services

# Install and configure fail2ban
sudo apt-get install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

# Enable automatic security updates
sudo apt-get install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades

Restart SSH Service

After configuration changes, restart the SSH service:

sudo systemctl restart sshd
# or
sudo service ssh restart

Security Benefits

Security Measure Benefit
Custom SSH Port Reduces automated scan attempts
Key-based Authentication Eliminates password-based attacks
Disabled Root Login Prevents direct administrator access
User Restrictions Limits access to authorized accounts
Firewall Rules Blocks unauthorized network traffic
Fail2ban Automatically blocks malicious IPs

Key Advantages

  • Reduced Attack Surface Non-standard ports avoid most automated scanning attempts

  • Strong Authentication Key-based authentication is significantly more secure than passwords

  • Access Control User restrictions and firewall rules limit potential attack vectors

  • Monitoring Capabilities Security services provide real-time threat detection

  • Automated Protection Fail2ban and automatic updates maintain ongoing security

Conclusion

Securing SSH requires a multi-layered approach combining port changes, strong authentication, access restrictions, and network security services. Proper hostname configuration aids system management, while firewall rules and automated security tools provide comprehensive protection against unauthorized access attempts.

Updated on: 2026-03-17T09:01:39+05:30

170 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements