Sign in with an SSH key and turn off password login
When your Linux server is delivered, the root user can sign in over SSH with a password. In this guide you will create an ed25519 key, test key-based login and then turn off password login without locking yourself out of the server.
Why turn off password login?
Every SSH port exposed to the internet quickly becomes a target for automated password-guessing (brute-force) bots. You can count the failed attempts reaching your own server:
# Ubuntu and Debian (service name ssh)
journalctl -u ssh --since "24 hours ago" | grep -c "Failed password"
# AlmaLinux (service name sshd)
journalctl -u sshd --since "24 hours ago" | grep -c "Failed password"With public key authentication, no password travels over the network: the private key stays on your computer, and only the public key is added to the server. Because there is no password to guess, brute-force attacks get nowhere.
On Hostimor Linux templates, root password login over SSH is enabled at delivery (PermitRootLogin yes, PasswordAuthentication yes). The service is unmanaged, so hardening these settings is up to you. The recommended order is:
- Create a key pair on your computer.
- Add the public key and test the login in a new terminal.
- Create a separate user with sudo rights.
- Turn off password login and verify the effective values.
- Optionally, change the SSH port.
Create an ed25519 key on your computer
Ed25519 is a short, strong key type supported by every current OpenSSH release. Linux and macOS ship with the OpenSSH client. On Windows 10 and 11, the ssh and ssh-keygen commands also work in PowerShell; if ssh -V does not return a version, add OpenSSH Client under Optional features in Windows Settings.
# The same command on Linux, macOS and Windows PowerShell
ssh-keygen -t ed25519 -C "laptop-2026"The -C label helps you recognize later which device a key belongs to. If you leave the passphrase the command asks for empty, anyone who obtains the private key file can connect straight to your server. Set a passphrase and add the key to ssh-agent so you do not have to type it for every connection:
# Linux and macOS
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519# Once, in PowerShell opened as Administrator:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
# In a regular PowerShell window:
ssh-add $env:USERPROFILE\.ssh\id_ed25519You end up with two files: id_ed25519 is the private key and must never be shared, while id_ed25519.pub is the public key you will add to the server. If a very old system does not support ed25519, you can generate an RSA key with ssh-keygen -t rsa -b 4096.
Add the public key to the server
You can add the public key in one of the three ways below. First display its contents; the output is a single line starting with ssh-ed25519:
# Linux and macOS
cat ~/.ssh/id_ed25519.pub
# Windows PowerShell
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub1. The SSH Keys tool in the client area
The SSH Keys tool on your service page is available on Linux servers only and accepts up to 20 keys. Paste the single-line public key starting with ssh-ed25519 or ssh-rsa into the box. The key is written while the server is running and VMware Tools (open-vm-tools on Linux) is active; a key saved while the server is off is applied once the server starts and VMware Tools is running. The panel writes keys to the ~/.ssh/authorized_keys file of the login user shown on the Sign-in Details card (root on Linux templates), between the # BEGIN WISECP and # END WISECP lines. Keys you add inside the server outside that section are kept. Because the tool relies on VMware Tools, do not remove the open-vm-tools package or stop its service.
2. With ssh-copy-id or PowerShell
On Linux and macOS, ssh-copy-id adds the key and sets the permissions correctly; on Windows, you do the same in PowerShell with a single line. Both methods ask for your root password one last time.
# Linux and macOS
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@203.0.113.10# Windows PowerShell
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@203.0.113.10 "umask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"3. Manually on the server
For security reasons, OpenSSH ignores directories and files with loose permissions: ~/.ssh must be 700, authorized_keys must be 600, and both must belong to the user in question. The command below appends the key to the end of the file, outside the panel's marked section.
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Paste the entire public key line between the quotes
echo "ssh-ed25519 AAAA...rest-of-the-key laptop-2026" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# AlmaLinux only: fix the SELinux labels
restorecon -Rv ~/.sshTest key-based login
Without closing your current SSH session, open a new terminal and connect with options that prevent a fallback to password login. If the session opens without a password prompt (only your passphrase may be requested), the key works:
# Tries the key only, without falling back to a password
ssh -o PreferredAuthentications=publickey -o PasswordAuthentication=no root@203.0.113.10
# Shows which method was used: ... using "publickey"
ssh -v root@203.0.113.10 true 2>&1 | grep -i "authenticated"After every change in this guide, test the connection in a new terminal before you close the working session. The open session is the fastest way to undo a mistake; if it is closed too, the VNC Console is your only way back in.
Create a separate user with sudo rights
Using a sudo-enabled user instead of root for daily work limits the impact of a mistaken command and shows in the logs who did what. You will also need this user if you later decide to disable root SSH login completely. Run the commands below as root and replace the example name deploy with a user name of your choice:
# Ubuntu and Debian (if sudo is missing on Debian, first run: apt install sudo)
adduser deploy
usermod -aG sudo deploy
# AlmaLinux
useradd -m deploy
passwd deploy
usermod -aG wheel deploy
# All distributions: copy root's authorized keys to the new user
install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
install -m 600 -o deploy -g deploy /root/.ssh/authorized_keys /home/deploy/.ssh/authorized_keys
# AlmaLinux only
restorecon -Rv /home/deploy/.sshIn a new terminal, connect with ssh deploy@203.0.113.10 and check that sudo whoami returns root. Sudo asks for the user's local password. Turning off SSH password login does not affect this password, so give the user a strong one.
The hardening file that turns off password login
On Ubuntu, Debian and AlmaLinux 9, /etc/ssh/sshd_config starts with the line Include /etc/ssh/sshd_config.d/*.conf. The files in that directory are read in alphabetical order, and for most OpenSSH settings the first value read wins. Files on templates such as 50-cloud-init.conf may contain PasswordAuthentication yes; if you give your file a name starting with 99-, that line is read first and your setting silently has no effect. That is why your file name should start with 00-. First look at the current state:
grep -n "^Include" /etc/ssh/sshd_config
ls -1 /etc/ssh/sshd_config.d/
grep -rEin "^\s*(PasswordAuthentication|KbdInteractiveAuthentication|PermitRootLogin)" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/Then create the hardening file:
cat > /etc/ssh/sshd_config.d/00-hardening.conf <<'EOF'
# SSH password login off, key-only login
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
PubkeyAuthentication yes
MaxAuthTries 3
EOF
chmod 644 /etc/ssh/sshd_config.d/00-hardening.conf| Setting | Value | Effect |
|---|---|---|
PasswordAuthentication | no | Turns off SSH password login. |
KbdInteractiveAuthentication | no | Turns off interactive password prompts through PAM. |
PermitRootLogin | prohibit-password | Root signs in with a key only; once your sudo user works, you can block it completely with no. |
PubkeyAuthentication | yes | Keeps key-based login enabled (the default value). |
MaxAuthTries | 3 | At most 3 authentication attempts per connection. |
Before applying the change, test the syntax and check the values the server will actually use with sshd -T. This command merges all files and prints the effective configuration.
# Syntax test: no output means no problems
sshd -t
# The values the server will actually use
sshd -T | grep -Ei "^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin|pubkeyauthentication|maxauthtries) "
# Apply (open sessions stay connected)
systemctl reload ssh # Ubuntu and Debian
systemctl reload sshd # AlmaLinuxThe output should include passwordauthentication no and kbdinteractiveauthentication no. Some versions list prohibit-password under its equivalent, without-password. Finally, confirm from a new terminal that password login is refused; on AlmaLinux, the error line may also list gssapi methods:
# From a new terminal: forces password login, which must be refused
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password root@203.0.113.10
# Expected reply: Permission denied (publickey...)If sshd -T still shows passwordauthentication yes, a file read before yours, or a line in sshd_config placed above the Include line, defines the setting first. Find that line in the grep output and fix it; also keep in mind that settings inside Match blocks apply only to the connections they match.
Optional: changing the SSH port
Moving SSH off port 22 reduces the noise of automated attempts in your logs, but it is not a real security layer; key-based login is what protects you. The order is critical: first open the new port in the firewall, register it with SELinux on AlmaLinux, and then configure SSH to listen on both ports during the transition. If you plan to install DirectAdmin on the server, choose another number, because 2222 is the panel's default port.
# 1) Open the new port in the firewall
ufw allow 2222/tcp # Ubuntu and Debian (UFW)
firewall-cmd --permanent --add-port=2222/tcp && firewall-cmd --reload # AlmaLinux (firewalld)
# 2) AlmaLinux only: register the new port with SELinux as an SSH port
dnf install -y policycoreutils-python-utils
semanage port -a -t ssh_port_t -p tcp 2222
# 3) Listen on both ports during the transition
printf 'Port 22\nPort 2222\n' >> /etc/ssh/sshd_config.d/00-hardening.conf
sshd -t
# 4) Apply. On Ubuntu, first check whether socket activation is in use:
systemctl is-active ssh.socket
# If "active" (the default on Ubuntu 24.04 and later):
systemctl daemon-reload
systemctl restart ssh.socket
# If "inactive", or on Debian:
systemctl restart ssh
# On AlmaLinux:
systemctl restart sshd
# 5) Check the listening ports
ss -tlnp | grep -E ":(22|2222)\b"On Ubuntu 24.04 and later, the port is held by ssh.socket through systemd socket activation rather than by sshd, so a port change is applied not with reload but with a daemon-reload and a restart of the socket. After confirming that you can connect with ssh -p 2222 deploy@203.0.113.10, delete the Port 22 line, repeat step 4 and remove the old SSH rule from the firewall. If you use Fail2ban, update the port in its jail settings as well.
Common errors and recovering from a lockout
| Error | Likely cause | Fix |
|---|---|---|
Permission denied (publickey) | The key was added for a different user, is not loaded in ssh-agent, or the permissions are wrong. | Look for bad ownership or modes in the server log and set the permissions to 700/600. |
Too many authentication failures | ssh-agent offers many keys and MaxAuthTries 3 runs out. | Use IdentitiesOnly yes in the client configuration. |
UNPROTECTED PRIVATE KEY FILE! | The private key file's permissions are too open. | chmod 600 ~/.ssh/id_ed25519; on Windows, check that only your own user can access the file. |
REMOTE HOST IDENTIFICATION HAS CHANGED | The server's host key changed because the operating system was reinstalled. | If you did the reinstall yourself, run ssh-keygen -R 203.0.113.10; if the change is unexpected, investigate first. |
| A password is still requested | A value in another file is read before yours. | Find the source with sshd -T and the grep output. |
Defining the key, user and port for each server on the client prevents both typos and the “Too many authentication failures” error; afterwards, typing ssh hostimor-vds is enough:
# On the client: ~/.ssh/config (Windows: %USERPROFILE%\.ssh\config)
Host hostimor-vds
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesThe SSH log on the server shows the detailed reason:
journalctl -u ssh -n 50 --no-pager # Ubuntu and Debian
journalctl -u sshd -n 50 --no-pager # AlmaLinuxIf you are locked out anyway, connect independently of the network with the VNC Console in the client area. The console opens a local session, so SSH settings do not affect it; you sign in with your user name and password. Fix 00-hardening.conf or temporarily move it away, test with sshd -t and reload the service. Because of the keyboard layout, special characters in your password may come out differently in the console; see the VNC Console guide for details.
The panel's Reset Root Password tool reaches the server through VMware Tools with the stored password, not over SSH, so turning off SSH password login does not break it. However, if you change the root password inside the server with passwd or lock the account, the panel can no longer sign in with the stored password and the reset fails. Change the root password from the panel and keep the open-vm-tools service running.
Frequently asked questions
How do I get into the server if I lose my private key?
Sign in with your password through the VNC Console, or create a new key pair and add the public key with the SSH Keys tool. As a precaution, it is good practice to generate a separate key on a second device and add it from the start.
Should I disable root login completely?
With prohibit-password, root can sign in with a key only; for most use cases this is enough. If you have tested key login with your sudo user, PermitRootLogin no is a stricter option. Panel tools work through VMware Tools, so this setting does not affect them.
Do I still need Fail2ban after turning off password login?
The attempts become futile, but they keep arriving and filling your logs. Fail2ban temporarily blocks IP addresses that keep trying and also protects other services that use passwords. For Windows servers, see the RDP security guide.
Related articles
- Your first 30 minutes on a new VDS or VPS: a post-setup checklist
- Setting up a Linux firewall with UFW and firewalld
- Blocking brute-force attacks on SSH and web services with Fail2ban
- Reach your server without SSH or RDP using the VNC Console
- Automatic security updates and rebooting after a kernel update
Thanks for your feedback!