This sshd error occurs when SSH authentication attempts are made with a username that doesn't exist on the remote system, or when user access is restricted by sshd configuration. The message appears in server logs when login is rejected.
The 'Invalid user' message in sshd logs indicates that the SSH daemon received an authentication attempt for a username that does not exist on the system, or the user exists but is not permitted to access via SSH due to configuration restrictions (AllowUsers/AllowGroups directives). This is commonly seen as 'input_userauth_request: invalid user [username]' in detailed logs. Unlike other SSH errors that may appear on the client, this message is logged on the server side and represents a failed authentication attempt.
First, confirm that the username you're trying to use actually exists on the target system. Log in locally or through another method (like console access) and check:
id usernameOr list all users:
cat /etc/passwd | grep usernameIf the command returns nothing or 'id: username: no such user', the account doesn't exist and needs to be created or you're using the wrong username.
Verify that you're using the correct username in your SSH command:
ssh username@hostnameCommon typos:
- 'root' vs 'route'
- 'admin' vs 'administrator'
- Forgetting the username entirely (connects as current user)
- Extra spaces or special characters
If you're using a config file, verify the Host entry:
cat ~/.ssh/configEnsure the User directive matches an actual account on the server.
On the remote server, examine the SSH configuration for access restrictions:
sudo grep -E 'AllowUsers|AllowGroups|DenyUsers|DenyGroups' /etc/ssh/sshd_configIf AllowUsers is set, only users in that list can connect:
AllowUsers user1 [email protected]/24If your username isn't listed, add it:
sudo nano /etc/ssh/sshd_config
# Edit AllowUsers line to include your username
AllowUsers user1 user2 youruser
# Save and restart sshd
sudo systemctl restart sshdSimilarly check AllowGroups and ensure your user's primary or secondary group is listed:
groups usernameCheck the user's shell configuration:
sudo grep ^username /etc/passwdThe output format is: username:x:uid:gid:comment:/home/username:/bin/bash
The last field is the login shell. If it's set to /bin/false, /sbin/nologin, or a non-existent shell, the user cannot log in. To fix:
sudo usermod -s /bin/bash usernameCommon invalid shells:
- /bin/false - explicitly disallows login
- /sbin/nologin - system account with no login
- /usr/sbin/nologin - another variant of nologin
Set the shell to /bin/bash, /bin/sh, or another valid shell from /etc/shells.
Review the SSH server logs to understand exactly why the user is invalid:
On Debian/Ubuntu:
sudo tail -f /var/log/auth.log | grep 'Invalid user'On RedHat/CentOS:
sudo tail -f /var/log/secure | grep 'Invalid user'Using journalctl (all systems):
sudo journalctl -u sshd -fLook for related messages:
- 'input_userauth_request: invalid user' - username doesn't exist
- 'not allowed because none of user's groups' - AllowGroups issue
- 'User ... from ... not allowed' - DenyUsers/AllowUsers restriction
Make a login attempt from your client while watching the logs to see the exact failure reason.
Check if the user is explicitly denied:
sudo grep -E 'DenyUsers|DenyGroups' /etc/ssh/sshd_configIf the user or their group is listed in DenyUsers or DenyGroups, they're explicitly blocked. Remove them:
sudo nano /etc/ssh/sshd_config
# Remove the user from DenyUsers line
# Or remove the group from DenyGroups line
# Save and restart
sudo systemctl restart sshdNote: When both AllowUsers/AllowGroups and DenyUsers/DenyGroups are set, a user must be allowed by both to gain access.
Run your SSH command with verbose flags to see detailed authentication process:
ssh -vvv username@hostnameWith three -v flags, you'll see:
- Which authentication methods are attempted
- Whether the server rejects before or after password prompt
- Configuration directives being evaluated
- Exact error message from the server
If the error appears before asking for a password, it's a user lookup/configuration issue (not a password issue). If it appears after entering a password, the user exists but auth is failing for another reason.
If you've confirmed the user doesn't exist and should exist, create it:
# Create user with home directory
sudo useradd -m -s /bin/bash newuser
# Or with specific UID/GID
sudo useradd -u 1001 -g 1001 -m -s /bin/bash newuser
# Set a password
sudo passwd newuser
# Verify creation
id newuserIf the user needs to be in the sshlogin group (referenced by AllowGroups):
sudo usermod -a -G sshlogin newuserAfter creation, try SSH access again.
PAM (Pluggable Authentication Modules): The 'Invalid user' check happens at the PAM level before password authentication. If PAM isn't configured correctly (missing pam_unix.so), users may be treated as invalid even if they exist. Check /etc/pam.d/sshd for proper configuration.
LDAP/Directory Services: On systems using LDAP, NIS, or other directory services, users might exist in the directory but not in local /etc/passwd. Verify with getent passwd username to check all configured sources, not just local files.
Brute Force Attacks: High volume of 'Invalid user' messages in logs usually indicates brute-force attacks scanning for common usernames. Implement fail2ban or rate limiting to block repeat offenders.
Windows OpenSSH: On Windows systems, if your username is the same as the hostname, user resolution can fail with this error. Use a different username or rename the computer.
SSH Keys vs Passwords: The 'Invalid user' error applies to both password and key-based authentication. If using keys, verify they're in the correct location (~/.ssh/authorized_keys on the server) and have correct permissions (600).
SELinux/AppArmor: Mandatory access control systems might prevent sshd from querying user databases. Check denial logs: sudo tail /var/log/audit/audit.log for SELinux or sudo journalctl -u apparmor for AppArmor.
Load key "/home/user/.ssh/id_rsa": invalid format
How to fix 'Load key invalid format' in SSH
Bad owner or permissions on /home/user/.ssh/config
How to fix "Bad owner or permissions on .ssh/config" in SSH
Error connecting to agent: Connection refused
How to fix "Error connecting to agent: Connection refused" in SSH
Connection closed by UNKNOWN port 65535
How to fix 'Connection closed by UNKNOWN port 65535' in SSH
Offending ECDSA key in /home/user/.ssh/known_hosts:line
How to fix "Offending ECDSA key in known_hosts" in SSH