Interview Prep/Linux/Networking, SSH and remote access

A team wants to know who is logged in and from where on a server right now and historically. Which commands?

BeginnerScenarioNetworking, SSH and remote access
Answer

Situation read → Session accounting files plus auth logs.

What I'd do →

w                                  # current sessions and what they're running
who -a
last -F -n 20                      # history from /var/log/wtmp
lastb | head                       # failed logins from /var/log/btmp
journalctl -u sshd --since today | grep Accepted

Why → wtmp holds logins, btmp failed attempts and the journal has the key fingerprint used.

Interview tip → Note that an attacker with root can edit these files, so ship them off-box.

All Linux questions Roadmap: Linux

More on Networking, SSH and remote access