127

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
    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 ? – Prof. Moriarty Apr 8 '10 at 10:23
  • 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 '10 at 10:28
  • You are correct. /etc/syslog.conf redirects AUTH to /var/logauth.log. Please write your answer so i can accept it :) – grigoryvp Apr 8 '10 at 10:31
  • 3
    On my servers, sshd logs to /var/log/secure. This is configured in /etc/rsyslog.conf, on the line beginning "authpriv.*" – Isaac Betesh Jun 20 '13 at 14:34
  • 1
    authpriv?? How the heck were we supposed to know that had anything to do with sshd? :-) – Spencer Williams May 31 '15 at 12:54
7

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
  • 143
    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 '12 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. – Spencer Williams Apr 23 '15 at 16:32
  • 28
    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 '15 at 16:00
  • 4
    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. – Bruno Bronosky Feb 17 '17 at 14:43
  • 1
    @JoelESalas The community doesn't decide which answers are accepted. – kasperd Feb 4 '18 at 13:10
157

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)

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

  • 8
    This answer. Other answer with green arrow is bogus. Change arrow. – meshfields Aug 4 '14 at 23:58
  • 5
    Why not use tail -f ... to monitor it in real time? Would this be an issue with larger log files? – ingh.am Feb 2 '15 at 12:12
  • 6
    less +F ... will 'tail' in real time, and it's much more powerful than tail – northben May 7 '15 at 15:45
  • 5
    And lnav is even better than less/tail – Wayne Werner Jan 13 '16 at 18:17
  • 8
    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/… – Brian Hellekin Jan 5 '18 at 16:25
16

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

  • 1
    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. – Attila Antal Oct 15 at 19:38
1

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

grep -rsh sshd /var/log |sort
  • 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 '17 at 17:27
1

You can tail -f /var/log/auth.log

  • 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 '17 at 1:56
  • @chicks That's funny. Answer with most votes is almost the same like this.. – Qback Feb 9 '18 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.