SSH into server with the root user created by cloud provider.
2. Update Server
Update Ubuntu packages.
$ apt update [ inform server about lastest updates available ]
$ apt list --upgradeable [ returns a list of upgradable packages. run after: $ apt update ]
$ apt upgrade [ Install latest updates ]
It is safer to only allow SSH conections via a key and not a password. Before disabling password authentication, make sure that you either have SSH key-based authentication configured for the root account on this server, or preferably, that you have SSH key-based authentication configured for an account on this server with sudo access.
$ timedatectl [ Show timezone info ]
$ dpkg-reconfigure tzdata [ Set the timezone interactively ]
$ apt install fail2ban
$ cd /etc/fail2ban
$ cp jail.conf jail.local [ Create a copy of config file. this wil be read automatically on service restart ]
$ nano jail.local [ Open file in Nano editor ]
[Sshd]
enabled=true
$ service fail2ban restart [ Restart fail2ban for services to run. ]
$ apt install unattended-upgrades [ Install ]
$ systemctl enable unattended-upgrades [ Enable ]
$ systemctl start unattended-upgrades [ Start ]
$ nano /etc/apt/apt.conf.d/50unattended-upgrades [ Set what to upgrade ]
$ nano /etc/apt/apt.conf.d/20auto-upgrades [ Set when to upgrade ]
$ sudo unattended-upgrades --dry-run --debug [ Confirm config ]
$ ufw allow OpenSSH [ Enable firewall to accept firewall connections OpenSSH over port 22 ]
$ ufw allow http [ Allow http over port 80 ]
$ ufw allow https [ Allow https over port 443 ]
$ sudo ufw allow from 119.18.38.68 to any port 5432 [ Allow Postgres port 5432 from iFactory office ]
$ sudo ufw allow from 118.88.24.53 to any port 465 [ Allow nodemailer to receive response from external mail host ]
$ ufw enable [ Enable firewall ]
$ sudo ufw disable [ Disable firewall ]
$ sudo ufw reload [ Reload firewall rules ]
$ ufw status verbose [ show current firewall ]
$ ufw deny [ deny a particular service or port ]
$ ufw status numbered [ show rules with a number - use number to delete a rule ]
$ ufw delete [ delete a port or service by its status rule number ]
$ adduser ifactory [ Create new user 'ifactory' ]
$ usermod -aG sudo ifactory [ Grant new user Sudo permssions ]
$ less /etc/group [ list all Ubuntu groups ]
'q' to exit list
$ passwd ifactory [ Set/change password for user 'ifactory' ]
$ groups ifactory [ Show if a user exists and its groups e.g. sudo ssl-cert ]
$ getent passwd | grep ifactory [ Search for a user ]