LuoboyunNo wish to host? New users get 1 GB of trial traffic for 24 hoursWorks with Clash / Mihomo; pay by Alipay, WeChat or cryptoTry 1 GB freeAdLuoboyun: 1 GB of trial trafficValid 24 hours; Alipay, WeChat, cryptoTry 1 GB freeAd
hi-ddify.org
A vault door is thick because everyone knows where it is

Security

A better lock for the server's door

A vault door is thick because everyone knows where it is Spamguy at English Wikipedia, CC BY 2.5

Public servers are guessed at all day. Keys, no passwords and another port in three steps, each with a way back.

The Hiddify Manager menu warns while password sign-in is on. The log shows why:

Server
journalctl -u ssh --since today | grep -c "Failed password"

Hundreds or thousands a day are common on a new machine.

From the first minute programs try passwords on every public server. They do not know you; they scan whole ranges. However safe the panel is, a guessed root password gives away every user's keys.

Step 1: make a key

On your own computer:

Your computer
ssh-keygen -t ed25519

Press Enter throughout. Send the public half with ssh-copy-id root@IP on Mac and Linux, or on Windows:

Windows PowerShell
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Sign in from another window; no password question means it works.

A key: switch SSH to key login and passwords cannot be guessed
A key: switch SSH to key login and passwords cannot be guessed Pittigrilli, CC BY-SA 4.0

Step 2: no passwords

Server
echo "PasswordAuthentication no" > /etc/ssh/sshd_config.d/00-key-only.conf
sshd -t && systemctl reload ssh

sshd -t checks the syntax and stops on an error. Keep the old window open.

Step 3: another port (optional)

It stops nobody determined but most of the noise. Allow the new port in the security group, change it, sign in with it, close 22 last. On Ubuntu 24.04 SSH listens through a systemd socket, so after changing Port also run:

Server
systemctl daemon-reload
systemctl restart ssh.socket
An SSH prompt in a terminal: test from a second window before logging out
An SSH prompt in a terminal: test from a second window before logging out Hpott, CC BY-SA 4.0

Ways back

RiskWay back
Key file lostA copy on a stick or in a password manager
Wrong settingThe host's web console
New computerAdd its key beforehand
  1. Key workschecked in another window
  2. Passwords offold window stays
  3. Port lastsecurity group first
Keep the order

Who is knocking

Server, the last day
journalctl -u ssh --since "24 hours ago" | grep "Failed password" | grep -oE "from [0-9.]+" | sort | uniq -c | sort -rn | head
last -n 5

If last shows an address you do not know, do not repair: back up the panel and reinstall.

Why keys are stronger

A password is sent and can be guessed. A private key never leaves your computer; the server asks a question only it can answer. With a passphrase a stolen file is useless too.

Where Windows users get stuck

Still asked for a password? Permissions on the server:

Server
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R root:root ~/.ssh

Before turning passwords off

  1. A new window logs in with the key.
  2. The private key has a copy elsewhere.
  3. The host's console opens and you know the root password.

Then check:

Your computer, should be refused
ssh -o PubkeyAuthentication=no root@IP

Permission denied (publickey) is right. If it still asks, another file in /etc/ssh/sshd_config.d/ such as 50-cloud-init.conf turns it on; the first name wins, hence 00-.

What changing the port does

A random five-digit port removes nine tenths of the noise. Not much safer, but real events become visible.

~/.ssh/config on your computer
Host home
    HostName 203.0.113.10
    Port 28022
    User root
    IdentityFile ~/.ssh/id_ed25519

Then ssh home is enough.

One more layer

With a fixed IP allow only it in the host's firewall. Keep the console as a way back. And turn on security updates:

Server
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
Official support asks to log in.

The menu has add_remote, only for when they ask; run remove_remote afterwards.

Is fail2ban still needed?

With passwords off, guessing is useless; it is up to you.

Copy the key between computers?

Better one pair per computer; if one is lost, remove its line.

A normal user with sudo?

Tidier, but Hiddify Manager needs root. Root with keys is acceptable for yourself.

Change the panel password too?

Yes, long and used nowhere else.

Two more to read

ChoosingA 1 GB machine for Hiddify: enough?The official minimum is one core and 1 GB. Whether it is enough depends on installing, running and people, and something else runs out first.InstallingPort 443 is taken. What nowIf Nginx, a hosting panel or another proxy already sits on the server, they fight for 80 and 443. Who holds them, and why not to mix.

While you are here

About: SSH key login, change SSH port, secure a VPS