Security
Protect your self-hosted VitNode app with these security measures.
Now, let's talk about security. Security is a crucial aspect of any deployment, especially when you're hosting your own app.
SSH Key Authentication
Using an SSH key to connect to your server is more secure than using a password. It's recommended to use SSH key authentication instead of a password.
Here we will generate an SSH key using Termius, an SSH client.
Generate SSH Key
In Termius, click on the "Settings => Keychain
" tab and then click on the "Generate" button on SSH Keys
section. Type label and passphrase for the key and click on the "Generate" button.
Save Public Key
After generating the SSH key, save the public key.
Add Public Key to Server
Create a new folder ~/.ssh
on the server and add the public key to the ~/.ssh/authorized_keys
file.
Paste the public key into the authorized_keys
file and save it by pressing Ctrl + X
, then Y
to confirm the changes and Enter
to save the file. Press again Enter
to exit the editor.
Change chmod for SSH File
Change the permissions for the ~/.ssh/authorized_keys
file and restart the SSH service.
Test connection to the server
Now try to connect to the server using the SSH key instead of a password.
Make sure you can connect to the server using the SSH key.
Your password is still required to use sudo
commands.
Edit Configuration File
To improve security, you have to edit the SSH configuration file and make some changes.
Open the configuration file:
Change SSH Port
Change the default SSH port from
to a custom port
Avoid using common ports like 22
, 2222
, etc.
Disable Root Login
Change from:
to:
Disable Password Authentication
Change from:
to:
Save & Restart
After making changes, save the file by pressing Ctrl + X
, then Y
to confirm the changes and Enter
to save the file. Press again Enter
to exit the editor.
Restart the SSH service to apply the changes:
Check if you can connect to the server using the new port and SSH key.
Cloud Config (Optional)
Sometimes when you have cloud providers like Hetzner, they create a 50-cloud-init.conf
file that overrides the SSH configuration. You need to remove this file to apply the changes.
Check password setting
Check the password settings on the server:
If the output is PasswordAuthentication no
, it means password authentication is disabled.
Fail2Ban
Fail2Ban is an intrusion prevention software framework that protects computer servers from brute-force attacks. It works by monitoring the server's logs for malicious activity and blocking the IP addresses of attackers.
This command will install Fail2Ban, enable it to start on boot, start the service, and check the status. If everything is OK, you should see the status as active
.
Disable IPv6
If you're not using IPv6, it's recommended to disable it.
Check IPv6
Check if IPv6 is enabled on the server:
If you see an IPv6 address, it means IPv6 is enabled.
Edit sysctl configuration file
Add the following lines to the end of the file:
After adding the lines, save the file by pressing Ctrl + X
, then Y
to confirm the changes and Enter
to save the file. Press again Enter
to exit the editor.
Firewall (UFW)
Uncomplicated Firewall (UFW) is a user-friendly frontend for managing iptables firewall rules. It's recommended to use UFW to manage the firewall rules.
Allow Custom SSH Port
If you changed the SSH port, you need to allow the new port:
Enable UFW
Enable UFW and check the status: