SSH "Permission denied, please try again": how to fix it

The SSH server rejected your password, or its settings don't allow password login for that account. Run `ssh -v` to see what is happening, then check the username, your key and its file permissions, and finally the server's effective `sshd` settings (for example `PermitRootLogin` and `PasswordAuthentication`).

Applies to:OpenSSH client, connecting to an OpenSSH server on Linux (systemd)Server-side steps (sudo, /var/log/auth.log or /var/log/secure) are written for Linux. Windows, macOS and BSD servers use different config paths, service managers and key-file rules, so those steps do not apply there.
On this page

What it means

OpenSSH prints Permission denied, please try again. when a password (or keyboard-interactive) attempt fails and the client is still allowed to retry. Once the attempts are used up, it ends with a final line such as Permission denied (publickey,password). The server's MaxAuthTries limit defaults to 6.

The message doesn't say which part is wrong. Either the server really did reject the credentials, or its configuration doesn't permit that login method for that user. A common surprise is logging in as root with a correct password and still being refused, because the server only accepts keys for root.

This article covers the password-prompt version of the problem. Work through the steps in order: the first ones only touch your own machine. The server-side steps assume a Linux server using systemd. If you are looking at a plain "Permission denied" in a local shell instead, see Permission denied in the Linux shell.

Symptoms and causes

You are likely dealing with this problem if:

  • The password prompt comes back two or three times with Permission denied, please try again.
  • The client then exits with Permission denied (publickey,password) or a similar line.
  • A root login is refused even though the password is definitely right (seen on cloud servers).

The usual causes, most common first:

Wrong username or password
A typo, a changed password or the wrong account name is the usual reason.
Root password login is blocked
The PermitRootLogin default is prohibit-password, which disables password and keyboard-interactive login for root but still allows keys. Older versions or distro packages may default differently.
Password authentication is turned off on the server
PasswordAuthentication defaults to yes.
The user is restricted by the server
Directives such as AllowUsers can limit who may log in. There is no restriction by default.
A key login fails silently and falls back to the password prompt
The client tries methods in this order: GSSAPI, host-based, public key, keyboard-interactive, password. If your key isn't offered, isn't in authorized_keys, or has wrong file permissions or ownership on either side, the password prompt is what you end up seeing.

How to fix it

Work through these in order. They start with the quickest, safest checks and move to deeper repairs; stop as soon as the problem is gone.

1.See what the client and server are doing

Easy

Verbose output shows which login methods the server offers and whether your key was tried, so you stop guessing.

  1. Run the connection again with verbose output. You can repeat -v up to three times for more detail.
    Terminal
    ssh -v user@host
    ssh -vvv user@host
  2. Read the lines near the end: they list the authentication methods the server accepts (for example publickey,password) and show which keys were offered.
  3. Confirm the username is exactly the account that exists on the server, then retype the password slowly. If the server only lists publickey, password login is disabled and you need a key or a server change (see the later fixes).

2.Point ssh at the right key

Easy

If your key has a non-default file name, ssh won't offer it and falls through to the password prompt.

  1. Name the key on the command line:
    Terminal
    ssh -i ~/.ssh/id_ed25519 user@host
  2. To make it permanent, add an IdentityFile line for that host in ~/.ssh/config.
  3. Make sure the matching public key is listed in ~/.ssh/authorized_keys for that user on the server.

3.Tighten the key and .ssh permissions

EasyChanges settings

The ssh manual says ~/.ssh should be accessible only by its owner, private keys must not be readable by others, and authorized_keys should be read/write for the user only. The server also checks ownership and modes by default (StrictModes yes in sshd_config(5)), so a home directory or .ssh that is too open or owned by the wrong user makes the server ignore your key.

Before you start: Change permissions only on your own .ssh directory and files.

  1. On the server, check that the account's home directory and .ssh belong to that user, and that the home directory is not writable by group or others.
    Terminal
    ls -ld ~ ~/.ssh ~/.ssh/authorized_keys
  2. If the home directory is group- or world-writable, remove that write permission. If any of the paths belong to another user, change the owner with chown (as root) to the account that logs in.
  3. Retry the login with ssh -v and check whether the key is now accepted. If it still fails, look in the server log (see the next fix).

4.Read the server's log

Moderate

The server logs the real reason for each rejection, which is usually more specific than the client message. You need console access or another working login.

  1. Look at the authentication log. It is /var/log/auth.log on Debian and Ubuntu and /var/log/secure on CentOS and RHEL.
    Terminalneeds sudo / root
    sudo tail -n 50 /var/log/auth.log
    sudo tail -n 50 /var/log/secure

5.Adjust the effective sshd settings on the server

AdvancedChanges settings

If the server doesn't allow password login, or doesn't allow it for root, no password will ever work until the configuration changes. SSH itself is refusing you, so use the provider's web console or other direct access.

Before you start: Keep an existing session or console open until the new login works. Allowing passwords or root login on an internet-facing host raises the risk of brute-force attacks, so prefer keys.

  1. Print the values the server is actually using. This shows the effective result, not just what one file says.
    Terminalneeds sudo / root
    sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|allowusers'
  2. Find which file sets each value. sshd uses the first value it reads for a keyword, so a drop-in can override a line you edit later in sshd_config.
    Terminalneeds sudo / root
    sudo grep -Ein 'passwordauthentication|permitrootlogin|allowusers|^include' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf
  3. Open the file that actually sets the value (the drop-in if that is where it lives) and change it there.
  4. To allow password logins, set PasswordAuthentication yes. For root, prefer keeping PermitRootLogin prohibit-password and logging in with a key. PermitRootLogin yes works with passwords but is less secure. Also check that no AllowUsers line excludes your account.
    Config
    PasswordAuthentication yes
    PermitRootLogin prohibit-password
  5. Check the configuration for errors before restarting.
    Terminalneeds sudo / root
    sudo sshd -t
  6. Run the sshd -T command from the first step again and confirm the values are what you intended, then try the login.
    Terminalneeds sudo / root
    sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|allowusers'

Check that it worked

  • ssh user@host logs you in without the Permission denied line.
  • ssh -v user@host shows the authentication succeeding with the method you expect (key or password).

If it still fails

  • Run ssh -vvv user@host and compare the offered methods with the output of sudo sshd -T on the server.
  • Read the server log for the exact rejection reason before changing more settings.
  • If this is a cloud server, use your provider's console or password-reset tools, and ask their official support if the account itself looks locked.

Questions

Why does root get refused with the right password?

The PermitRootLogin default of prohibit-password disables password login for root while still allowing keys. Distro packages or older versions may behave differently, so check the effective value with sudo sshd -T.

My guide says ChallengeResponseAuthentication. Is that the same thing?

It is a deprecated alias for KbdInteractiveAuthentication, so older guides still use the old name.

Sources

  1. sshd_config(5) manualOfficial · OpenBSD
  2. ssh(1) manualOfficial · OpenBSD
  3. What do I do if the "Permission denied, please try again" error message appears when I log on to a Linux instance as the root user by using SSH · Alibaba Cloud