Skip to content

Disable SSH password login

If you have already set up an SSH key, we recommend disabling password login. Automated guessing of your account password will then no longer allow access to the VPS through SSH. For a typical personal server, this is one of the most useful security measures.

This guide is for Ubuntu 24.04 LTS and 26.04 LTS. It does not remove your system password: you may still need it for sudo or to log in through your hosting provider's console. Settings for direct root login, the SSH port, existing keys and the firewall are not changed.

Before you begin

Verify key-based login first

Do not disable password login until you have verified that you can open a new SSH connection using your key and obtain root privileges. Keep a backup of your private key. Leave the current working SSH session open until all checks are complete. Ideally, verify access to the VPS emergency console in your provider's control panel beforehand.

If you do not have a key yet, follow the SSH keys guide for Termius or Windows first.

Complete the shared preparation below, then choose one of the two methods. Both create the same file. You do not need to use both.

For both methods: how to undo the change · final verification.

Connect to the VPS using your usual SSH account. If it is not root, run:

sudo -i

Verify that you are running as root:

whoami

The expected result is root. Run all remaining server commands in this session as root.

This guide assumes Ubuntu's standard OpenSSH configuration. If you or your provider have set up additional Match rules (conditions for individual users or addresses), non-standard configuration files or two-factor SSH authentication, check them first. Global settings may be overridden for individual connections, and disabling interactive authentication may affect the second factor.

Option 1. Manual configuration

1. Create a separate configuration file

On Ubuntu, the main SSH server configuration file is /etc/ssh/sshd_config. It usually includes additional files from /etc/ssh/sshd_config.d/ near the beginning. OpenSSH reads them in alphabetical order and uses the first value found for most options.

We will therefore create 00-3x-ui-no-password.conf, which is read before a typical cloud-init file. This avoids editing your hosting provider's original settings and makes the change easy to undo.

First, check whether the file already exists:

ls -l /etc/ssh/sshd_config.d/00-3x-ui-no-password.conf

If it exists, do not blindly overwrite it. If it does not exist (the command reports that the file could not be found), open the editor:

nano /etc/ssh/sshd_config.d/00-3x-ui-no-password.conf

Insert these three lines:

PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
  • PubkeyAuthentication yes allows SSH key authentication.
  • PasswordAuthentication no disables ordinary password login.
  • KbdInteractiveAuthentication no disables interactive authentication, which can also allow the server to prompt for a password.

In nano, press Ctrl+O, then Enter to save, and Ctrl+X to exit.

2. Verify the configuration before applying it

sshd -t

On success, the command prints nothing. If an error appears, do not apply the changes: correct the file or remove it using the rollback instructions.

Now check which settings OpenSSH will actually obtain from all the configuration files:

sshd -T | grep -E '^(pubkeyauthentication|passwordauthentication|kbdinteractiveauthentication|authenticationmethods) '

For a typical server, expect:

pubkeyauthentication yes
passwordauthentication no
kbdinteractiveauthentication no
authenticationmethods any

The order of the lines may differ. The value authenticationmethods publickey is also suitable because it requires key authentication. If the values differ or output is missing, do not continue. Check the priority of other configuration files and your provider's settings. If Match rules exist, you also need to verify the settings for the specific connection (see the OpenSSH documentation below).

3. Apply the changes

Only after a successful check, run:

systemctl reload ssh.service

This reloads the SSH server configuration. There is no need to reboot the VPS. Do not close the old session. Proceed directly to the final login check. You do not need to follow the second method.

Option 2. Ready-to-run script

If you prefer not to edit the file manually, copy the entire block and run it on the VPS as root in the working SSH session you already have open. Before running it, verify a new key-based login as described above.

The script first writes the settings to a temporary file, then creates a separate configuration file without overwriting an existing one. It verifies the syntax and effective global SSH settings before reloading the configuration. On error, it attempts to remove the file it created. If applying the settings fails, it also reloads the previous configuration. If rollback is not confirmed, keep the working session open.

bash <<'EOF'
set -e
file=/etc/ssh/sshd_config.d/00-3x-ui-no-password.conf

if [ "$(id -u)" -ne 0 ]; then
    echo "Error: run sudo -i and try again."
    exit 1
fi

if [ -e "$file" ] || [ -L "$file" ]; then
    echo "File already exists: $file. Check it manually."
    exit 1
fi

sshd -t
umask 077
tmp=$(mktemp "${file}.XXXXXX")
trap 'rm -f -- "$tmp"' EXIT
cat > "$tmp" <<'CONF'
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
CONF
ln -T -- "$tmp" "$file"

if ! sshd -t ||
   ! config=$(sshd -T) ||
   ! grep -qx 'pubkeyauthentication yes' <<< "$config" ||
   ! grep -qx 'passwordauthentication no' <<< "$config" ||
   ! grep -qx 'kbdinteractiveauthentication no' <<< "$config" ||
   ! grep -Eq '^authenticationmethods (any|publickey)$' <<< "$config"; then
    if rm -- "$file"; then
        echo "SSH validation failed. The new file was removed; no reload was performed."
    else
        echo "Could not remove $file. Keep the current session open."
    fi
    exit 1
fi

if ! systemctl reload ssh.service; then
    if rm -- "$file" && sshd -t && systemctl reload ssh.service; then
        echo "Failed to apply SSH settings. The previous configuration was reloaded."
    else
        echo "SSH rollback was not verified. Keep the current session open. Check $file and ssh.service."
    fi
    exit 1
fi

echo "Settings applied. Verify a new SSH key login."
EOF

The success message means the server accepted the settings. It does not replace checking a new SSH connection. Proceed to the final verification.

Final verification

1. Make sure the key works

On your computer or phone, open a new connection to the same VPS in Termius with the selected key. If you use PowerShell, connect using the key-based login test.

In the new terminal, check that you logged in as the correct user. If it is not root, also verify that you can run sudo -i. A private key passphrase or a password prompt from sudo does not mean SSH password login is still enabled.

2. Make sure password login is disabled

Do not repeat failed login attempts

If you enabled enhanced VPS security when installing 3X-UI AUTO NGINX, Fail2ban may temporarily block your IP address after failed SSH login attempts. One test is enough. Do not guess passwords or repeat the command if the server has already refused the connection. Keep the old working session open.

On your computer in PowerShell or another terminal with OpenSSH, not on the VPS, run:

ssh -o ControlPath=none -o BatchMode=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes -o KbdInteractiveAuthentication=yes -o PreferredAuthentications=password,keyboard-interactive -o NumberOfPasswordPrompts=1 root@YOUR_VPS_IP

Substitute the VPS IP and the user you successfully logged in as with a key. If direct root login is disabled, use your own account, for example ubuntu. For a non-standard SSH port, add -p PORT after ssh.

The command opens a new connection without reusing an existing SSH session and deliberately disables key authentication on the client side. It allows password-based methods on the client to check whether the server offers them. On a typical server with password login disabled, it ends with a message such as:

Permission denied (publickey).

If the server prompts for your account password or an interactive code, or if the refusal message lists password or keyboard-interactive as available methods, do not enter a password. Cancel the command with Ctrl+C and check the configuration. A timeout or TCP connection refusal does not prove that password login is disabled.

If a new key-based connection works, administrator privileges are available and password login is rejected, the setup is complete. You can now close the old session.

Where the file is stored and how to undo the change

Both methods create the same file:

/etc/ssh/sshd_config.d/00-3x-ui-no-password.conf

To undo only this setting, remove the file created by this guide and reload the configuration from the working root session you kept open:

rm -- /etc/ssh/sshd_config.d/00-3x-ui-no-password.conf &&
sshd -t && systemctl reload ssh.service

Do not delete other files from sshd_config.d. After removing the file, the settings from the remaining files take effect again, so password login is restored only if it was previously allowed. If key-based login fails after the change, perform this rollback before closing the old session. If you lose all SSH sessions, use your hosting provider's emergency console.

Add an SSH key · Enhanced VPS security · All guides

Attribution and use of materials

© 2026 xPROMSx contributors · 3X-UI AUTO NGINX

Our material may be copied and distributed under the GNU GPL-3.0-only license, provided the attribution and link to the original are retained.

Original source: https://xpromsx.github.io/3x-ui-auto-nginx/guides/ssh-password/

Terms of use for project materials