温馨提示×

linux ssh登录日志在哪

小樊
33
2026-10-14 06:10:00
栏目: 智能运维

在 Linux 系统中,SSH 登录相关的日志位置和格式取决于你使用的 发行版 和 init 系统。下面按常见情况说明:


一、常见发行版日志位置

1. CentOS / RHEL 6 及以前(syslog)

/var/log/secure

SSH 登录成功、失败、断开都会记录在这里。

查看示例:

grep sshd /var/log/secure

2. CentOS 7 / RHEL 7 / Rocky / Alma(systemd)

日志由 journald 管理:

journalctl -u sshd

查看登录成功/失败:

journalctl -u sshd | grep "Accepted"
journalctl -u sshd | grep "Failed"

3. Ubuntu / Debian

老版本:

/var/log/auth.log

查看 SSH 登录:

grep sshd /var/log/auth.log

新版本(systemd):

journalctl -u ssh

二、SSH 登录日志常见关键字

  • 登录成功:
    Accepted password for user from IP port
    
  • 登录失败:
    Failed password for user from IP port
    
  • 无效用户:
    Invalid user xxx from IP
    
  • 断开连接:
    Connection closed by IP
    

三、实时查看 SSH 登录

tail -f /var/log/auth.log
# 或
journalctl -u sshd -f

四、常见补充

  • SSH 服务配置文件:/etc/ssh/sshd_config
  • 登录失败次数过多可能被 fail2ban 记录
  • 日志轮转文件:
    /var/log/auth.log.1
    /var/log/secure-20260101
    

如果你能告诉我 具体发行版和版本号,我可以给你更精确的命令。

0 踩