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`).
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
PermitRootLogindefault isprohibit-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
PasswordAuthenticationdefaults toyes.- The user is restricted by the server
- Directives such as
AllowUserscan 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
Verbose output shows which login methods the server offers and whether your key was tried, so you stop guessing.
- Run the connection again with verbose output. You can repeat
-vup to three times for more detail.ssh -v user@host ssh -vvv user@host - Read the lines near the end: they list the authentication methods the server accepts (for example
publickey,password) and show which keys were offered. - 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
If your key has a non-default file name, ssh won't offer it and falls through to the password prompt.
- Name the key on the command line:
ssh -i ~/.ssh/id_ed25519 user@host - To make it permanent, add an
IdentityFileline for that host in~/.ssh/config. - Make sure the matching public key is listed in
~/.ssh/authorized_keysfor that user on the server.
3.Tighten the key and .ssh permissions
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.
- On the server, check that the account's home directory and
.sshbelong to that user, and that the home directory is not writable by group or others.ls -ld ~ ~/.ssh ~/.ssh/authorized_keys - 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. - Retry the login with
ssh -vand 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
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.
- Look at the authentication log. It is
/var/log/auth.logon Debian and Ubuntu and/var/log/secureon CentOS and RHEL.sudo tail -n 50 /var/log/auth.log sudo tail -n 50 /var/log/secure
5.Adjust the effective sshd settings on the server
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.
- Print the values the server is actually using. This shows the effective result, not just what one file says.
sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|allowusers' - 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.sudo grep -Ein 'passwordauthentication|permitrootlogin|allowusers|^include' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf - Open the file that actually sets the value (the drop-in if that is where it lives) and change it there.
- To allow password logins, set
PasswordAuthentication yes. For root, prefer keepingPermitRootLogin prohibit-passwordand logging in with a key.PermitRootLogin yesworks with passwords but is less secure. Also check that noAllowUsersline excludes your account.PasswordAuthentication yes PermitRootLogin prohibit-password - Check the configuration for errors before restarting.
sudo sshd -t - Run the
sshd -Tcommand from the first step again and confirm the values are what you intended, then try the login.sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|allowusers'
Check that it worked
ssh user@hostlogs you in without thePermission deniedline.ssh -v user@hostshows the authentication succeeding with the method you expect (key or password).
If it still fails
- Run
ssh -vvv user@hostand compare the offered methods with the output ofsudo sshd -Ton 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
- sshd_config(5) manualOfficial · OpenBSD
- ssh(1) manualOfficial · OpenBSD
- 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