w to see who is logged in now, last for past logins and sudo lastb for failed ones. For details from the SSH service itself, run sudo journalctl -u ssh (Ubuntu/Debian) or sudo journalctl -u sshd (AlmaLinux/Rocky), or read /var/log/auth.log (Ubuntu) or /var/log/secure (AlmaLinux/Rocky).
Before you start
w,whoandlastwork for any user. Failed logins and the system logs needsudo. Root users can leave outsudo.- Know your own IP address, so you can tell your logins apart from others.
- Debian 13 changed how logins are recorded. See the Debian tab in each section.
How to see who is logged in right now
FROM is the IP address the session came from. who shows the same list in a shorter form.
To end a session you do not recognise, note its TTY and run sudo pkill -KILL -t pts/1. Then change that user’s password or SSH keys straight away.
How to see past logins
- Ubuntu / AlmaLinux / Rocky
- Debian 13
-i shows IP addresses instead of host names and -n 20 limits the list to 20 lines. To see logins since a date, use last -i -s 2026-11-01.lastlog (tested on Ubuntu 24.04). On Debian 13, install the lastlog2 package and run lastlog2.
How to see failed SSH login attempts
- Ubuntu / Debian
- AlmaLinux / Rocky
Ask the SSH service log directly:On Ubuntu you can also search the text log:
sudo lastb -i -n 20 lists failed logins on Ubuntu. Debian 12 and 13 do not create /var/log/auth.log unless you install rsyslog, and Debian 13 has no lastb, so use journalctl there.Invalid user means the user name does not exist. Failed password for alex means someone tried a real user name, which is more serious.
How to count which IP addresses attack the most
-u sshd on AlmaLinux/Rocky. Hundreds of attempts from the internet are normal for any server with SSH open. Fail2Ban or CrowdSec block them automatically, and disabling password login makes them useless.
How to see successful SSH logins only
publickey or password). A password login when you only use keys, or an IP you do not know, needs action.
What to do if you find a login you do not recognise
- Note the user, IP address and time.
- Check what that user changed:
sudo cat /home/USER/.bash_historyandsudo ls -la /home/USER/.ssh/. - Follow what to do if your Linux server is hacked.
Frequently asked questions
Why does journalctl -u ssh show nothing on AlmaLinux?
The service is namedsshd there. Use journalctl -u sshd.
Why is last empty?
The login record file may have been rotated, or you are on Debian 13 withoutwtmpdb. Use last -f /var/log/wtmp.1 for the previous file, or search the journal instead.
How long are login logs kept?
It depends on your log rotation and journal size settings. Check the journal withjournalctl --disk-usage and see read logs with journalctl.
Are hundreds of failed logins a sign I have been hacked?
No. Bots scan every public IP address for SSH and try common passwords. They are only a problem if a login succeeds, so check theAccepted lines.
Related guides
VPS and dedicated server guides
Every guide in this section.
Read logs with journalctl
Filter any service log.
Set up Fail2Ban
Ban IPs that keep failing.
Disable root login
Stop direct root logins.
Server hacked?
Steps to recover safely.
Checked against the Debian 13 release notes, the Debian wtmpdb notes and the util-linux manuals on 4 November 2026;
w, who, last, lastb, lastlog and journalctl were tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026