Log into your server as root
.
ssh root@your-server-ip-address
apt-get update
apt-get upgrade
Change your password. A strong password is recommended.
passwd
In my case, I created an "deploy" user.
adduser deploy
usermod -a -G sudo deploy
Generate SSH keys on your local computer.
ssh-keygen
Make home and ssh directories for the new user.
mkdir /home/deploy
mkdir /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
Upload your public key to your server.
scp ~/.ssh/id_rsa.pub deploy@your-server-ip-address:
Move the public key to .ssh
directory.
mv id_rsa.pub /home/deply/.ssh/authorized_keys
Modify permissions of ssh keys.
chmod 400 /home/deploy/.ssh/authorized_keys
chown deploy:deploy /home/deploy -R
vim /etc/ssh/sshd_config
Change the values below.
PermitRootLogin no
PasswordAuthentication no
AllowUsers newUserName
Restart SSH service.
services ssh restart
apt-get install fail2ban
We use ufw
, a front end for iptables
, to configure our fire wall.
ufw allow ssh
ufw allow http
ufw allow https
ufw enable
Run ufw status verbose
to show status. You can also find what has happened to iptables by typing the following command.
iptables -L