A server you rent is yours to secure. ConfigServer Firewall (CSF) is the usual first step on a Linux server: it controls which ports are reachable and, through its login-failure daemon, blocks addresses that keep guessing passwords.
These steps assume you are connected over SSH as root.
Install it
cd /usr/local/src
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csfThen run the installer that matches the server:
./install.cpanel.sh # a server running cPanel/WHM
./install.directadmin.sh # a server running DirectAdmin
./install.generic.sh # a server with no hosting panelCSF installs into /etc/csf and picks up the ports currently in use.
Before you walk away
- Open
/etc/csf/csf.confand check that your SSH port is inTCP_IN. Locking yourself out is the classic first mistake. - Restart the firewall so the rules apply:
``
bash csf -r`` - When you are sure you can still connect, take it out of testing mode: set
TESTING = "0"in/etc/csf/csf.confand restart again. WhileTESTINGis 1, the rules are flushed every few minutes and protect nothing.
Important
Keep the server's management panel to hand while you work — it is how you get back in if a rule shuts you out. See Access your VPS or dedicated server.
Useful commands
csf -a 203.0.113.10 # allow an address
csf -d 203.0.113.10 # block an address
csf -g 203.0.113.10 # see why an address is blocked
csf -tf # clear all temporary blocks