1.1 Create a non-root user
For security, we would like to login in SSH via a non-root user
- shell
adduser vpsadminset password and follow prompts
install
sudoshellapt update apt install sudoadd
vpsadmintosudolistshellvisudounder
User Privilege Specification, addvpsadmin ALL=(ALL) NOPASSWD: ALLsave
Ctrl + oand exitCtrl + x(in nano)⚠️Critical Security Risk To add
vpsadminto thesudogroup in a safer way, I suggestshellusermod -aG sudo vpsadminThis requires your password everytime, but the attacker won't instantly gain full
rootcontrol of your server without needing a password.verify the user has sudo access (optional)
shellsu - vpsadmin sudo whoamiIt should prompt for your password and output "root"
1.2 Switch SSH login port
- shell
vim /etc/ssh/sshd_config - pick a number from
, and set it as your port - find
#Port 22, uncomment it, and change it to your port- example:
Port 3145
- example:
- save
:wand exit:q(in vim)vim:wq - restart ssh serviceshell
systemctl restart ssh - (important) test the new port before closing your current ssh session
- open a new terminal on your local machine and try:shell
ssh -p 3145 vpsadmin@YOUR_SERVER_IP - if it fails, do not logout from the old session (check firewall / provider rules first)
- open a new terminal on your local machine and try:
1.3 Disable Root Login
- open
/etc/ssh/sshd_configviavimshellvim /etc/ssh/sshd_config - find
PermitRootLogin yes, uncomment it (if necessary), and change it tonoto disable direct root accessPermitRootLogin no - save and exitvim
:wq