Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SSH Log File Location on Linux Servers

· 5 min read · Home Tech

In this article
  1. Why SSH Logs Matter
  2. Default Log Locations by Distribution
  3. How SSH Logging Works
  4. How to Read and Search SSH Logs
  5. Common Problems and Misconceptions
  6. Security and Privacy Considerations
  7. Alternatives to Traditional Log Files
  8. Frequently Asked Questions

The SSH log file on a Linux server is typically located at /var/log/auth.log on Debian/Ubuntu systems and /var/log/secure on RHEL/CentOS/Fedora systems. These files record all SSH authentication attempts, including successful logins, failed password attempts, and connection errors.

Why SSH Logs Matter

SSH is the primary remote administration protocol for Linux servers, so its logs are critical for security auditing and troubleshooting. They provide a chronological record of every connection attempt, allowing administrators to detect brute-force attacks, unauthorized access, and configuration issues. For example, a sudden spike in failed login attempts from a single IP address often signals an automated attack. Logs also help verify that legitimate users are connecting from expected locations and at expected times.

Default Log Locations by Distribution

The exact path depends on your Linux distribution and its logging configuration. The two most common locations are:

  • Debian/Ubuntu: /var/log/auth.log – contains all authentication-related events, including SSH.
  • RHEL/CentOS/Fedora: /var/log/secure – similar purpose, but also includes other security events like sudo usage.
  • Arch Linux: Uses /var/log/auth.log if rsyslog is installed, but the default is often journald (see below).
  • openSUSE: /var/log/messages may contain SSH entries, but /var/log/secure is also used on some versions.

If you are unsure, check the SSH server configuration file /etc/ssh/sshd_config for the SyslogFacility directive. The default is usually AUTH, which sends logs to the auth facility, ending up in the files above. If it is set to DAEMON, logs go to /var/log/daemon.log or /var/log/messages.

How SSH Logging Works

SSH server (sshd) uses the syslog protocol to send messages to the system logger. The logger (rsyslog or syslog-ng) then filters and writes them to specific files based on the facility and priority. The facility is auth (or authpriv), and priorities range from debug to emerg. For example, a successful login is typically logged at info priority, while a failed password attempt is logged at notice or warning. The syslog configuration in /etc/rsyslog.conf or /etc/rsyslog.d/ determines which file receives these messages. On systemd-based systems, the journal also captures these messages, which can be queried with journalctl.

How to Read and Search SSH Logs

Logs are plain text, so you can use standard tools like grep, tail, and less. To see recent SSH activity:

sudo tail -f /var/log/auth.log

To search for failed attempts:

sudo grep "Failed password" /var/log/auth.log

To show accepted logins:

sudo grep "Accepted" /var/log/auth.log

For systemd-based systems, you can use journalctl directly:

sudo journalctl -u ssh --since today

This shows all messages from the ssh service. Use journalctl -u sshd on RHEL-based systems. You can also combine with grep for filtering.

Common Problems and Misconceptions

One common issue is that the log file is empty or missing. This usually happens when rsyslog is not running, or the file was rotated and deleted. Check if rsyslog is active with systemctl status rsyslog. Another misconception is that all SSH logs are in one place – but if you have multiple SSH daemons or use a non-standard port, logs still go to the same file, but you may need to filter by port. Also, failed SSH attempts are often logged with the message "Connection closed by authenticating user" – this is normal and not an error. Finally, remember that log rotation (via logrotate) creates compressed older files like auth.log.1.gz; use zcat or zgrep to read them.

Security and Privacy Considerations

SSH logs contain sensitive information such as usernames and IP addresses. Restrict access to these files to root and admins only. The default permissions are usually 640 with root:adm ownership, which is fine. Never delete or truncate logs without a backup if you need them for forensic analysis. Also, be aware that logs can be tampered with by an attacker with root access – consider sending logs to a remote syslog server for integrity. Additionally, enabling verbose logging (LogLevel VERBOSE) in sshd_config provides more detail but increases disk usage.

Alternatives to Traditional Log Files

On modern systemd distributions, the journal is the primary logging system. You can view SSH logs with journalctl -u ssh without needing a separate file. However, many admins still have rsyslog configured to forward journal messages to text files for easier analysis. Another alternative is to use a centralized log management tool like ELK (Elasticsearch, Logstash, Kibana) or Graylog, which aggregates logs from multiple servers. These tools often require installing an agent on each server to forward logs. For quick local analysis, you can also use sshguard or fail2ban which monitor log files and block offending IPs – they read the same log files described above.

Frequently Asked Questions

How do I find the SSH log file if it's not in the default location?

Check the rsyslog configuration in /etc/rsyslog.conf and /etc/rsyslog.d/ for lines containing auth or authpriv. Also, run sudo grep -r "auth" /etc/rsyslog* to see where messages are directed. If you use journald, all logs are in the journal, so you can query with journalctl.

Can I change where SSH logs are stored?

Yes. You can modify the rsyslog configuration to send auth messages to a custom file. For example, add a line like auth,authpriv.* /var/log/ssh.log to a file in /etc/rsyslog.d/ and restart rsyslog. Alternatively, set SyslogFacility in sshd_config to a different facility, but that affects all SSH logs.

Why do I see "Failed password for invalid user" in the logs?

This means someone tried to log in with a username that does not exist on the system. It's a common sign of automated brute-force attacks. You can ignore them if you have strong passwords, but consider using fail2ban to block repeat offenders.

How do I monitor SSH logs in real time?

Use tail -f /var/log/auth.log or journalctl -f -u ssh. This will stream new log entries as they happen. You can also use watch to run a grep command periodically.

What is the difference between auth.log and secure?

They serve the same purpose but are used by different distributions. auth.log is Debian/Ubuntu, secure is RHEL/CentOS. Both record authentication events, including SSH, sudo, and login attempts. The content format is nearly identical.

Are SSH logs readable by regular users?

No. The files are typically readable only by root and members of the adm group (on Debian/Ubuntu) or root and wheel (on RHEL). This is to protect sensitive information. If you need to give a user access, add them to the appropriate group, but be cautious.