brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: lastb lists failed login attempts on a Linux server

Linux
~/tips/tip-security-lastb-failed-logins

sudo lastb | head -n 20

Shows the log of bad login attempts that Linux keeps in /var/log/btmp.

A server with SSH open to the internet gets knocked on all day. lastb shows who tried and failed, if the system recorded it.

sudo lastb | head -n 20
sudo lastb -i | head

The util-linux manual says lastb is the same as last, except that by default it shows the log in /var/log/btmp, which holds all the bad login attempts. It needs root, since that file is not readable for normal users.

Useful options come from last: -i shows the IP address instead of a hostname, -s sets a start time, and -f reads another file, such as a rotated one.

It is a quick sanity check after you changed something. If you turned off password logins for SSH, you expect the same attempts to keep coming, but none should succeed.

The caveat is that the log may be empty or missing. The file does not exist if nothing was ever written to it, and a guide I read notes that failed SSH logins are not always recorded in btmp, depending on the configuration. So an empty result does not prove nobody tried. On a systemd machine the journal is the other place to look, with journalctl -u ssh, whose unit is called sshd on some distributions.

Further reading: last(1) manual, util-linux

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link