Updates
Updating packages and dependencies:
Enable automatic updates for existing packages:
Enable automatic updates:
User
Create a new user:
Give it a secure password! Only login via this user not using root! This will be your password to access the server via ssh, so hackers will try to bruteforce.
Add user to sudo group:
SSH
Change ssh port:
# Port 22 → Port 535
| use anything between 0-1023 (Well Known Ports range)
Only use IPv4:
AddressFamily any → AddressFamily inet
Dont let Root login:
PermitRootLogin yes → PerminRootLogin no
Disable password login:
# PasswordAuthentication yes → PasswordAuthentication no
Only apply this when you generated an SSH key!
Generate SSH key
Generate SSH key pair on the server:
It will create the files server-admin
(the private key) and server-admin.pub
(the public key). The option -N ''
tells to the command ssh-keygen
to generate a key pair without password.
We want to append the public key to ~/.ssh/authorized_keys
, but first let’s make sure that the directory exists and has propper permissions:
Login with private key
We want to transfer the private key to our local machine (laptop). We can just copy/paste its content or we can use scp
like this:
Now let’s try to login using this private key:
To make things easier, let’s create a configuration file on ~/.ssh
(on the local machine):
Firewall
Install Firewall ufw (Uncomplicated Firewall):
Allow ssh port:
Enable ufw:
Fail2ban
Install Fail2ban:
Check status: