Contents
- First, ask yourself the right question.
- Who is online right now?
- Login history and last command limits
- Look for successful SSH logins in the authentication logs
- Do not count failed attempts as logged in users
- File logs, rotations, and missing history
- Which person and which activity: correlation has its limits
- Practical outcome of the inspection and further steps
- Frequently asked questions
First, ask yourself the right question.
The query "who is logged in" can mean who is currently connected, who logged in yesterday, who tried an incorrect password, or who made a specific change. A different source is used for each query. The list of active sessions is not a history, and the history of interactive terminals is not a complete audit of all commands and transmissions over SSH.
Linux usually records the account, time, and depending on the mechanism, the source address or authentication method used. This data does not automatically identify a person. A shared administrator account can be used by several people; the same public IP can belong to many clients behind NAT. Therefore, distinguish between a documented event and your interpretation, and when submitting your findings, write down exactly what the record actually proves.
The examples are read-only and assume administration of your own Linux server. Some records can only be read by an administrator or a member of the appropriate group. Gaining access to a log is not a reason to change its rights for everyone. Use the necessary permissions wisely and do not expose the contents of the logs on a public website.
Who is online right now?
Start with a general overview of interactive logins and sessions. The who aw commands show different views of logged sessions. On a systemd system, loginctl can also be useful. Terminal names, idle time, and source help determine what to do next, but may not capture all types of SSH usage.
who
w
loginctl list-sessions
# U konkrétního ID ze seznamu:
loginctl session-status ID_RELACEReplace ID_RELACE with the actual identifier. A non-interactive command, SFTP, or tunnel without a pseudo-terminal may not appear the same as a regular shell. A single administrator can have multiple sessions, and multiple terminal windows can share a single SSH transport. The number of lines does not automatically indicate the number of people or the number of TCP connections.
For the network context, you can read ss -tnp with appropriate permissions and find the relevant processes. However, the established TCP connection alone does not prove successful authentication: it may be before. Do not terminate a suspicious process based on an unknown address without checking the context; it may be an approved automation or bastion.
Login history and last command limits
On many distributions, last reads history from the wtmp file. The summary can show account, terminal, time, and exit, and possibly system reboots. Availability and format depend on the distribution and package; some systems use a different mechanism. A non-existent command or an empty file is not proof that no one has logged in to the machine.
# Příklady pro last z util-linux:
last -F -i -n 30
last -F -i -n 20 spravce
last -x -n 20
# Záznam posledního přihlášení, pokud je nástroj na systému dostupný:
lastlogThe -F and -i options in util-linux print full times and IPs instead of name resolution. For other implementations, follow their help. Check how far back in history you actually go, whether the log is rotating, and where the approved archives are. The still logged in mark is not independent evidence that a person is actively working; the record may have been left incomplete by a crash or unexpected disconnection.
Compare the history with reboots and system time. Changing the clock can complicate session length calculations. Lastlog shows the last recorded login for an individual account, not the full sequence of its operations. Neither last nor lastlog by themselves will tell you which specific public key was received in yesterday's SFTP transfer.
Look for successful SSH logins in the authentication logs
On Ubuntu and Debian with systemd, start with the ssh.service journal; on systems with a different name, use sshd.service. Choose a limited time window. Reading the entire multi-year log can be unnecessarily slow and it's easy to miss important context. For a specific incident, use an explicit time zone and a comparable output format.
sudo journalctl -u ssh.service --since "-24 hours" \
-o short-iso --no-pager
# Další pohled podle identifikátoru, pokud tak systém SSH loguje:
sudo journalctl -t sshd -t sshd-session --since "-24 hours" \
-o short-iso --no-pagerLook for messages indicating that authentication was accepted, such as Accepted publickey or Accepted password, and the subsequent session opening. Note the account, source address, time, and available key fingerprint. The presence of this information depends on the version and logging level; do not assume that every distribution will print identical lines.
Newer OpenSSH can split the work between multiple processes, so a single guessed program name may not be enough. If the first filter doesn't show anything, check the actual identifiers and backend. The goal is not to add ever-bigger filters, but to find a record of a known custom audit login. This will prove that the source is actually collecting the type of event you are monitoring.
Do not count failed attempts as logged in users
Invalid user or Failed password are failure records. They do not have the same meaning as accepted authentication. A public server may record many automated attempts without a single successful intrusion. On the other hand, a few suspicious successes may be more serious than thousands of commonly rejected passwords.
# Na instalacích, které vedou btmp a mají lastb z util-linux:
sudo lastb -F -i -n 30
# Stav případné používané ochrany:
sudo fail2ban-client status sshdLastb and Fail2ban are only available where appropriate mechanisms are in place. Ban counts are not the number of successful attacks or the total number of attempts. Filters, rotations, and retention change the available view. Compare sources and event definitions before adding, otherwise you may count the same failure twice or compare different periods.
For shared addresses and automation, also check for legitimate reasons for failure: old key, bad profile, or planned migration. A known office IP does not necessarily mean the attempt was made by the right person. Consider the available key identity and follow-up events, not just a geographic guess at the address.
File logs, rotations, and missing history
Some installations keep authentication events in /var/log/auth.log, others in /var/log/secure, others only in the journal or on a remote collector. Verify the path first. For rotated files, older copies may be compressed. The incident time window may be in a previous rotation, even though the current file appears empty.
# Pouze pokud tato souborová cesta na vaší distribuci existuje:
sudo grep -E "Accepted |Failed |Invalid user" /var/log/auth.log
# Journal: rozsah uložených bootů a jeho obsazené místo
sudo journalctl --list-boots
sudo journalctl --disk-usageA volatile journal may lose history after a restart; retention may remove older periods. Therefore, specify the limits of available data when auditing. Later increasing the logging level or enabling persistent storage will not restore data that was not previously created or has already been deleted. A missing record cannot be replaced by an estimate issued as a guarantee.
Do not delete or clean up logs as a first step when an incident is suspected. Ensure an adequate copy of the necessary evidence with controlled access and record the origin and time of acquisition. A local log can be modified by an attacker with sufficient privileges, so independent remote collection is important for a stronger audit. Its implementation is a separate operational change.
Which person and which activity: correlation has its limits
Link account events to individual key inventory, approved bastion access, and scheduled tasks. For certificates, a recorded serial number and identifier can help if the issuance process is trusted and the necessary data is logged. A single shared private key for the entire team makes reverse human resolution significantly worse.
A login does not tell you who modified a particular file. Shell history can be incomplete, changeable, and may not contain exact times; it is not a full audit trail. Sudo, auditd, or approved session logging provide other kinds of evidence and must be set up properly beforehand. You cannot retroactively promise a detailed command log that the system did not collect.
When correlating PIDs, consider process number reuse and reboots. The same PID on a different day may not mean the same session. For source addresses, consider proxies, VPNs, and NAT. The credibility of a header or rewritten address depends on the actual network path set, not what the client itself stated.
Practical outcome of the inspection and further steps
Write the result as a concise summary of the verified events: time zone, server, account, accepted method, available fingerprint or certificate, source, and log used. Separate successful logins, failed attempts, and unexplained events. Indicate how far back the history goes and which types of sessions the source does not capture.
- The actual control login is traceable in the selected source.
- The times of the client, server and possible bastion are comparable.
- Suspicious success is verified against the account, key, and approved work.
- Missing or unreliable records are explicitly listed.
- In the event of an incident, documentation is maintained and the response is based on the actual scope of authorization.
You can open a terminal in CH-J Tools and perform the above read checks, but the application will not create a server audit trail that does not exist. If you find an unexplained login received, first confirm the context and address the access or compromise based on the result. Simply blocking one address does not prove that the stolen key has been revoked or subsequent changes have been removed.
Frequently asked questions
Will who show all SSH connections?
No. It focuses on logged logins and non-interactive commands, tunnels, or SFTP may not be seen in the same way as a terminal.
Is a Failed password proof of a successful attack?
No. This is a rejected attempt. Look for success in the received authentication and the subsequent session context.
Can I identify a specific person by IP?
Usually not reliably. The address may be shared by multiple clients and may belong to a VPN or bastion. You need additional trusted evidence.
Does an empty log prove that no one logged in?
No. Check the correct backend, permissions, retention, rotation, and whether the event type being tracked was even recorded.
Detailed documentation
systemd: journalctl and log filtering →
OpenSSH: server, authorization and logging →