219

I have Ubuntu 9.10 installed with sshd and I can successfully connect to it using login and password. I have configured an RSA key login and now have "Server refused our key" as expected. Ok, now I want to check sshd log in order to figure out a problem. I have examined /etc/ssh/sshd_config and it have

SyslogFacility AUTH
LogLevel INFO

Ok. I'm looking at /var/log/auth.log and... it's empty O_O. Changing Loglevel to VERBOSE helps nothing - auth.log is still empty. Any hints how I can check sshd log?

7
  • 10
    Did you check your syslog configuration? I don't run Ubuntu, but it may redirect the AUTH facility to a different logfile. Maybe /var/log/messages ? Apr 8, 2010 at 10:23
  • 1
    How to check a syslog configuration? Unfortunately, i'm not very good a linux :(. cat /var/log/messages | grep ssh shows nothing :(.
    – grigoryvp
    Apr 8, 2010 at 10:28
  • 2
    You are correct. /etc/syslog.conf redirects AUTH to /var/logauth.log. Please write your answer so i can accept it :)
    – grigoryvp
    Apr 8, 2010 at 10:31
  • 2
    On my machine: The system logs are set in /etc/rsyslog.conf, which in turn includes /etc/rsyslog.d/* The actual file setting the location of the logs is /etc/rsyslog.d/50-default.conf. Apr 8, 2010 at 11:53
  • 7
    On my servers, sshd logs to /var/log/secure. This is configured in /etc/rsyslog.conf, on the line beginning "authpriv.*" Jun 20, 2013 at 14:34

9 Answers 9

15

If no one else is using the system at the moment you could do what i've done in such cases:

  • stop sshd service (at least i've been able to do this while logged in via ssh)
  • start sshd manually and add some -d options to get more verbose debug output. Unless you have something funky going on it should use the same keys and config it does when started properly
16
  • 208
    Stopping SSHD on a remote server is a really bad idea. This may solve the problem for some (or most) setups most of the time, but if ANYTHING goes wrong - your connection, power on either end, forgetfulness, etc - you're locked out of the box. Which is bad news.
    – Sudowned
    Nov 21, 2012 at 18:58
  • 1
    Well, it should be noted that the only way you could start the service after manually stopping it would be to have some other kind of access to it, like another non-SSH remote connection, or you're sitting in front of it. Apr 23, 2015 at 16:32
  • 55
    How does this answer the question? I landed here from a web search expecting to learn how to check the SSHD log files, not what worked for you for some problem... Damn I wish readers on the Stack Exchange network would actually read and answer the question at hand, and not the question they want it to be....
    – user145545
    Aug 23, 2015 at 16:00
  • 6
    You can start another sshd on another port. Connect to that one. Then stop the main sshd and start a new one on port 22. If anything fails, reboot the box using your DRAC or cloud management. You should have sshd starting on boot right? No worries. Feb 17, 2017 at 14:43
  • 3
    @JoelESalas The community doesn't decide which answers are accepted.
    – kasperd
    Feb 4, 2018 at 13:10
261

Creating an answer based on the comments above, credit to @Prof. Moriarty and @Eye of Hell

SSH auth failures are logged here /var/log/auth.log

The following should give you only ssh related log lines:

grep 'sshd' /var/log/auth.log

To be on the safe side, get the last few hundred lines and then search (because if the log file is too large, grep on the whole file would consume more system resources, not to mention will take longer to run)

View sshd entries in the last 500 lines of the log:

tail -n 500 /var/log/auth.log | grep 'sshd'

or to follow the log output as you test:

tail -f -n 500 /var/log/auth.log | grep 'sshd'
9
  • 16
    This answer. Other answer with green arrow is bogus. Change arrow.
    – user54883
    Aug 4, 2014 at 23:58
  • 10
    Why not use tail -f ... to monitor it in real time? Would this be an issue with larger log files?
    – ingh.am
    Feb 2, 2015 at 12:12
  • 12
    less +F ... will 'tail' in real time, and it's much more powerful than tail
    – northben
    May 7, 2015 at 15:45
  • 5
    And lnav is even better than less/tail Jan 13, 2016 at 18:17
  • 19
    P.s.: if your server is a Red Hat (as CentOS), the path of sshd/login records log is /var/log/secure (check /var/log folder for the log files of specific dates too). See this answer: serverfault.com/questions/465833/… Jan 5, 2018 at 16:25
56

The modern way to view logs:

  1. All messages about sshd:
    journalctl -t sshd
    or
    journalctl -u ssh where -u == unit

  2. Messages about sshd from the last boot:
    journalctl -t sshd -b0

  3. Messages about sshd from the last boot in the reverse order:
    journalctl -t sshd -b0 -r

3
  • 2
    Yep !!! Also journalctl -u ssh, where u = unit . With this syntax you can use for any systemd unit
    – MarcoZen
    Apr 19, 2021 at 19:08
  • 1
    I tried -u sshd and it didn't work, but -u ssh works, thanks!
    – RedEyed
    Apr 21, 2021 at 12:23
  • I tested -u ssh ( 32 seconds ) vs -t sshd ( 10 seconds ) on my home server. It appeared that -t sshd is 3 times faster.
    – Alek_A
    Nov 28, 2023 at 16:46
50

If you can try the failing connection again easily, one way easy way is to start an SSH server on a free port such as 2222:

/usr/sbin/sshd -d -p 2222

and then retry the connection with:

ssh -p 2222 user@host

By using the different port -p 2222, we don't have to stop the main SSH server, which could lock us out.

See also: https://unix.stackexchange.com/a/55481/32558

4
  • 6
    One of the best options, specially if you only have SSH access to a server. Debugging the connection by stopping the ssh server will drop you out of session. Just start a new ssh daemon on a different port and test the login using that port. Oct 15, 2019 at 19:38
  • 2
    @AttilaAntal Small correction: stopping sshd will not kill active ssh sessions. This method is a good precaution in case something goes wrong, but in theory you can easily stop and then restart sshd over ssh. Feb 9, 2020 at 3:35
  • 1
    @ParkerKemp it doesn't kill the connection, and if everything is working as expected, you should be able to continue using it after after restarting the daemon. The problem, however, will be if for some reason the Daemon couldn't start. Then the active session will drop. Feb 10, 2020 at 15:35
  • use sudo and absolute path if you can not create host key
    – True
    Aug 1, 2023 at 3:15
9

If you want to see all log messages about sshd, run this:

grep -rsh sshd /var/log |sort
3
  • 2
    Logs will start with entries like Mar 14 19:52:04 which exclude the year and are not easily sorted (though you may get lucky with sort --month-sort assuming you don't go over a boundary between years). The log files themselves are already sorted, so you just have to scan them in the right order. Also, the recursive grep -r call will be really slow on systems with large logs. There's no reason to additionally scan things like your HTTPD logs.
    – Adam Katz
    Aug 14, 2017 at 17:27
  • thx, i didn't know what flavor i was on, but this helped me find /var/log/secure (i actually ended up changing the command to grep -Rsl sshd /var/log but +1 for getting my thinking cap to appear).
    – WEBjuju
    Dec 4, 2019 at 0:01
  • 1
    tail -5000f /var/log/messages|grep -i sshd Feb 16, 2020 at 18:26
5

You can use the following command to see the logs from SSH:

tail -f /var/log/auth.log
2
  • 1
    Welcome to ServerFault. Did you read the question? He isn't getting data in that file. tailing it useless if it doesn't have any data in it.
    – chicks
    Nov 10, 2017 at 1:56
  • @chicks That's funny. Answer with most votes is almost the same like this..
    – Qback
    Feb 9, 2018 at 7:27
2

You might find the following commands useful as well:

sudo journalctl --system --follow
sudo journalctl --system --follow | grep -i ssh
1
  • You can also use sudo journalctl --system --follow -u ssh.service to monitor only ssh unit. Dec 6, 2022 at 4:48
1

Not for topicstarter, but for another opensuse tumbleweed users:

systemctl status sshd.service
journalctl -xeu sshd.service

The first gives you the status and time of fault:

 sshd.service - OpenSSH Daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Wed 2022-06-15 19:15:20 MSK; 10min ago

The second may give you more details, something like:

Jun 15 19:15:19 localhost.localdomain sshd[2124]: 
/etc/ssh/sshd_config.d/sshd.conf line 121: Directive 'usepam' is not allowed within a Match block
-2

In CentOS 7. I have found out SSH logs over here:

$ tail /var/log/audit/audit.log
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .