Your auth.log is full of Failed password and Invalid user attempts
Failed password for invalid user admin from 198.51.100.23 port 40122 ssh2Short answer
Any public SSH port gets password guesses within hours; the log lines alone are not a breach. First confirm there is no Accepted line from an address you do not know. Then turn password logins off and keep root out in sshd, which removes the risk, and add a fail2ban sshd jail only to cut the noise and the load.
Fix it fast
1Find out which cause you have
Separate noise from damage. Count the failures and list the busiest sources, then look for the one line that matters: a successful login. If an Accepted line shows an address or user you do not recognise, stop and treat the server as compromised instead of following this page.
# Debian and Ubuntu with a log file; use journalctl -u ssh if /var/log/auth.log does not exist sudo grep -c "Failed password" /var/log/auth.log sudo grep -E "Failed password|Invalid user" /var/log/auth.log | grep -oE "from [0-9a-f.:]+" | sort | uniq -c | sort -rn | head sudo grep "Accepted" /var/log/auth.log | tail -n 20 last -i | head -n 202Match what you see, then jump to its fix
- 1
sshd -T shows passwordauthentication yes, or the failures include root and common user names such as admin or test.Password and root logins are still allowed, so guesses can succeedFix - 2
The same few addresses appear thousands of times, and fail2ban is not installed or no sshd jail is listed.Nothing blocks a source address that keeps retryingFix - 3
fail2ban-client status sshd shows Currently failed: 0 and Total failed: 0 while the log keeps filling.The jail is on but never counts a failureFix - 4
Connections time out or are refused for you only, and your IP appears in the jail's banned list.A legitimate user or your own address got bannedFix
- 1
What does the error look like?
Failed password for invalid user admin from 198.51.100.23 port 40122 ssh2Invalid user ubnt from 198.51.100.23 port 40122Failed password for root from 198.51.100.23 port 40130 ssh2Connection closed by authenticating user root 198.51.100.23 port 40130 [preauth]
Cause 1 of 4
Password and root logins are still allowed, so guesses can succeed
1Check
Read the effective settings, not just the main file. Include files are read in name order and the first value found for a keyword wins, so a drop-in such as 50-cloud-init.conf on cloud images can keep passwords on after you edit sshd_config.
sudo sshd -T | grep -iE '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin|pubkeyauthentication|maxauthtries)'
ls /etc/ssh/sshd_config.d/2Fix
Install your public key first and prove it works in a second terminal. Then turn off password and keyboard-interactive logins (PAM challenge-response can act like a password) and root login. Name the file so it sorts before any other drop-in that sets the same keywords.
sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
MaxAuthTries 3
EOF
sudo sshd -t && sudo systemctl reload ssh # unit is sshd on RHEL-style systems3Verify
sshd -T now shows the new values, a key login from a new terminal works, and a forced password attempt is refused.
sudo sshd -T | grep -iE '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin)'
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no deploy@203.0.113.10Confirmed by man.openbsd.org
Cause 2 of 4
Nothing blocks a source address that keeps retrying
1Check
fail2ban reads the log, counts failures per address within a time window and asks the firewall to drop that address for a while. Check whether it is installed and which jails run.
systemctl is-active fail2ban
sudo fail2ban-client status2Fix
Install fail2ban and enable the sshd jail in a local file; never edit jail.conf itself, as package updates replace it. Put your own address in ignoreip so a typo cannot lock you out. This lowers noise and CPU use; the key-only settings above are what actually protect the account.
sudo apt install fail2ban
sudo tee /etc/fail2ban/jail.d/sshd-local.conf >/dev/null <<'EOF'
[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 203.0.113.50
[sshd]
enabled = true
mode = aggressive
maxretry = 4
findtime = 10m
bantime = 1h
EOF
sudo fail2ban-client -t && sudo systemctl restart fail2ban3Verify
The jail is listed, and its failed and banned counters rise as attempts arrive.
sudo fail2ban-client status sshdConfirmed by raw.githubusercontent.com
Cause 3 of 4
The jail is on but never counts a failure
1Check
fail2ban must read the place where sshd actually writes. A minimal Debian or Ubuntu image may log only to the systemd journal, with no auth.log, and a jail pointed at the wrong source sees nothing. Test the filter against the log by hand.
ls -l /var/log/auth.log
sudo fail2ban-client get sshd logpath
sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf | tail -n 82Fix
If there is no auth.log, make the jail read the journal. If the file exists but the path is unusual, set logpath for the jail explicitly. Restart and watch the counters.
# /etc/fail2ban/jail.d/sshd-local.conf, in the [sshd] section
backend = systemd
# or, for a log file in a non-default place
# logpath = /var/log/auth.log3Verify
Make a few failed logins from a machine that is not in ignoreip; the Total failed counter should rise.
sudo fail2ban-client status sshdConfirmed by raw.githubusercontent.com
Cause 4 of 4
A legitimate user or your own address got banned
1Check
Look at the banned list from another route, such as the provider console, and check whether your address is in it.
sudo fail2ban-client status sshd2Fix
Release the address and add it, or its network, to ignoreip so it is not counted again. Do not lower the protection to avoid the lock-out.
sudo fail2ban-client set sshd unbanip 203.0.113.50
# then add the address to ignoreip in the jail file and reload
sudo fail2ban-client reload3Verify
The address no longer appears in the banned list, and ssh connects.
sudo fail2ban-client status sshdConfirmed by manpages.debian.org
How do I stop it coming back?
- Treat keys-only login as the protection and fail2ban as a noise filter; never rely on the ban list alone.
- Check for Accepted lines from unknown addresses on a schedule, not just the failure counts.
- Limit who may log in with AllowUsers or AllowGroups, and restrict port 22 in the firewall to known networks when you can.
- Keep your own addresses in ignoreip and keep a console or second access path to the server.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Security
SSH refuses your key and ends with Permission denied (publickey)
user@203.0.113.10: Permission denied (publickey,password).
The server accepted the connection but found no key it would take.
5 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fixSecurity
Inline base64 images do not show because of the Content Security Policy
Refused to load the image 'data:image/svg+xml;base64,...' because it violates the following Content Security Policy directive: "default-src 'self'".
A base64 image has a data: URL, and a policy such as default-src 'self' does not allow that scheme.
3 causes, each with a fixSecurity
Video from a MediaSource is blocked: 'Content at ... may not load data from blob:'
Content-Security-Policy: The page's settings blocked the loading of a resource (media-src) at blob:http://localhost:3000/...
A MediaSource video plays from a blob: URL.
3 causes, each with a fixSecurity
The browser refuses to load a font because of your Content Security Policy
Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.
A font is blocked when the font-src directive, or default-src when font-src is missing, does not allow where the font comes from.
3 causes, each with a fixSecurity
The browser blocks a script because of your Content Security Policy
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
The page's Content-Security-Policy does not allow what it tried to run or load.
5 causes, each with a fix