jcaleb
New Member
Hello,
This is a simple way on how I secure my VPS.
On fresh install, login as root. First create a user you will use to login later, because we will disable root login after a while.
adduser jon
From your client machine, you will want to copy your key to this user on your server. So that you can have passwordless login.
If you don't have ssh keys on your client machine, do this first before above, to generate your key pair.
Again the ssh-keygen and ssh-copy-id are to be executed on your client machine, not from server. I only have linux as my client desktop, I don't know how to do this otherwise on a Windows desktop, sorry.
Now try to login to your server without providing password. If you can login successfully, then good.
ssh jon@your-ip-address
Edit ssh server config. And change the port to some random high value (E.g. 55190). Disable root login, and password authentication
I assume we want ssh server and not dropbear. I dont know how to do this in dropbear.
Next is firewall
Create a file to contain firewall rules
pico /etc/iptables.up.rules
and place the ff. contents
You can apply the firewall by running
But we want it to run on restart, so create a script file
And put the contents
And make it executable
Then reboot your server and try to login. (Because I dont know how to apply above without restarting. And restarting makes me feel more secured. )
If you can't login after this, then there is a problem =)
Click here to view the article
This is a simple way on how I secure my VPS.
On fresh install, login as root. First create a user you will use to login later, because we will disable root login after a while.
adduser jon
From your client machine, you will want to copy your key to this user on your server. So that you can have passwordless login.
Code:
ssh-copy-id jon@your-ip-address
Code:
ssh-keygen
Now try to login to your server without providing password. If you can login successfully, then good.
ssh jon@your-ip-address
Edit ssh server config. And change the port to some random high value (E.g. 55190). Disable root login, and password authentication
Code:
sed -i "/Port/cPort 55190" /etc/ssh/sshd_config
sed -i "/PermitRootLogin/cPermitRootLogin no" /etc/ssh/sshd_config
sed -i "/PasswordAuthentication/cPasswordAuthentication no" /etc/ssh/sshd_config
Next is firewall
Create a file to contain firewall rules
pico /etc/iptables.up.rules
and place the ff. contents
Code:
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
-A OUTPUT -j ACCEPT
# Allows SSH connections to our new ssh port
-A INPUT -p tcp --dport 55190 -j ACCEPT
# Open Other TCP Ports (like 80 if you will install a webserver). add more lines like this if you like
-A INPUT -p tcp --dport 80 -j ACCEPT
# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Reject all other inbound - default deny unless explicitly allowed policy
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT
Code:
iptables -F
/sbin/iptables-restore < /etc/iptables.up.rules
Code:
pico /etc/network/if-pre-up.d/iptables
Code:
#!/bin/sh
/sbin/iptables-restore < /etc/iptables.up.rules
Code:
chmod +x /etc/network/if-pre-up.d/iptables
Code:
ssh jon@your-ip-address -p 55190
Click here to view the article
Last edited by a moderator: