SSH is a common way into a Linux server, so its log messages are worth knowing. They let you check that only expected people log in to your systems.
Find the messages
The unit is ssh on Debian and Ubuntu and sshd on Fedora and RHEL.
sudo journalctl -u ssh --since todayNewer OpenSSH releases split work into a sshd-session process. Filtering by process name sshd alone could miss lines, so filtering by unit or facility is safer. With socket activation, unit names can differ, so check what your system logs.
Successful logins
Accepted publickey for deploy from 198.51.100.4 port 50514 ssh2: ED25519 SHA256:Xk3v...
Accepted password for alice from 192.0.2.17 port 40022 ssh2You see the method, user, source address and port. For public keys, the fingerprint identifies which key was used. Compare it with your authorised keys:
ssh-keygen -lf ~/.ssh/authorized_keysRecent OpenSSH versions print one fingerprint per key in that file.
Failures
Failed password for alice from 203.0.113.9 port 51022 ssh2
Invalid user admin from 203.0.113.9 port 51030
Failed password for invalid user admin from 203.0.113.9 port 51030 ssh2invalid user means no such account is allowed to log in on that host. One connection can produce several lines, so counting lines is not the same as counting attempts or attackers. Failed public key offers may not appear at the default log level.
Count source addresses:
sudo journalctl -u ssh | grep 'Failed password' | grep -oE 'from [0-9a-fA-F.:]+ port' | awk '{print $2}' | sort | uniq -c | sort -rnAct on what you see
Repeated failures from the internet are common. A success that you cannot explain is far more serious, especially after many failures. Check the user, address, time and key.
To reduce risk, use key authentication and set PasswordAuthentication no, KbdInteractiveAuthentication no (it can otherwise still prompt for a password) and PermitRootLogin no in the server configuration. Test a key login in a second terminal before you close your current one, and run sudo sshd -t to check the syntax. Distributions may include extra files from sshd_config.d, so sudo sshd -T shows the effective settings.
Try it
Log in to your own test server with a wrong password once, then correctly. Find both messages. Practise SSH in the networking and SSH lab.
Check your understanding
SSH Login Events
All 4 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.