LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-26-2008, 11:47 AM   #1
Excalibre
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Rep: Reputation: 0
Can I make SSH take better logs?


I'm running OpenSSH on Ubuntu Hardy and I have it set to only allow me, only via my private key, etc, so I'm feeling fairly comfortable. But I'm curious about all these apparently ubiquitous automatic attacks on SSH servers -- is there a way to make SSH log them? I can tell it's not logging every attempt to log in, because when I tried experimentally logging in without a private key (as though I was a bot waiting for a chance to try a password), my SSH session unceremoniously ended but nothing appeared in auth.log. In fact, the only attempt I've seen in auth.log was one attempt to log in as root (which is of course not allowed) and it didn't even record the damn IP address!

So what I'd like is logs of attempts that fail because I use private key authentication, and I'd also like to see the dang IP addresses. I don't really know what I'm doing here so any help is appreciated.
 
Old 09-26-2008, 12:19 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
There are two values in 'sshd_conf' that can me modified to produce more log output:
Code:
LogLevel [QUIET|FATAL|ERROR|INFO|VERBOSE|DEBUG|DEBUG1|DEBUG2|DEBUG3]
# and
SyslogFacility [DAEMON|USER|AUTH|LOCAL0|LOCAL1|LOCAL2|LOCAL3|LOCAL4|LOCAL5|LOCAL6|LOCAL7]
The default's are in bold. I would leave 'SyslogFacility' alone, but you can increase LogLevel to Verbose to get more output. Also, sshd will log through syslog. So try looking for info in '/var/log/messages' or '/var/log/syslog' (whichever one you have). Here's a little one-liner that will show you all sshd logs:
Code:
grep sshd /var/log/messages
# or
grep sshd /var/log/syslog

I've been getting a lot of brute-force ssh attacks lately too. After one ip tried 3000 times, I decided to do something. You can setup /etc/hosts.allow and /etc/hosts.deny to block a single ip or allow ssh access from only listed ips:
/etc/hosts.deny
Code:
# to deny specific ip(s)
sshd : <ip1> <ip2> ..
Code:
# to only allow certain ips:
# in /etc/hosts.deny place this
sshd : ALL

# in /etc/hosts.allow
sshd : <ip> <ip> etc
There are various ways to use those two files (there are ways to do everything through hosts.allows without having to touch hosts.deny).

Last edited by CRC123; 09-26-2008 at 12:21 PM.
 
Old 09-26-2008, 12:51 PM   #3
Excalibre
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by CRC123 View Post
There are two values in 'sshd_conf' that can me modified to produce more log output:
Code:
LogLevel [QUIET|FATAL|ERROR|INFO|VERBOSE|DEBUG|DEBUG1|DEBUG2|DEBUG3]
# and
SyslogFacility [DAEMON|USER|AUTH|LOCAL0|LOCAL1|LOCAL2|LOCAL3|LOCAL4|LOCAL5|LOCAL6|LOCAL7]
The default's are in bold. I would leave 'SyslogFacility' alone, but you can increase LogLevel to Verbose to get more output.
Okay, thanks! Done.


Quote:
Also, sshd will log through syslog. So try looking for info in '/var/log/messages' or '/var/log/syslog' (whichever one you have). Here's a little one-liner that will show you all sshd logs:
Code:
grep sshd /var/log/messages
# or
grep sshd /var/log/syslog
Checked both, neither of them have anything SSH related.
 
Old 09-26-2008, 01:18 PM   #4
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
I forgot to mention, that you need to restart the sshd service through one of these ways (I don't know how ubuntu does it):
Code:
/etc/init.d/sshd restart
# or
rcsshd restart
# or
service sshd restart
one of those should restart it.

Also, after some reading, it looks like ssh in ubuntu logs to /var/log/auth.log, so after you restart ssh, check there.
 
Old 09-26-2008, 01:30 PM   #5
Excalibre
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Right, already done, and it did in fact log an attempt (by me) to log in without a password afterwards. Unless I'm not looking in the right place, though, I'm not getting the once-a-minute bot attempts that a lot of people were talking about.
 
Old 09-26-2008, 01:43 PM   #6
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
Quote:
Originally Posted by Excalibre View Post
Right, already done, and it did in fact log an attempt (by me) to log in without a password afterwards. Unless I'm not looking in the right place, though, I'm not getting the once-a-minute bot attempts that a lot of people were talking about.
The attempts are pretty random (as far is I'm concerned). yesterday i would get hit by random ip's for hours straight, then they would stop. I would be 'unattacked' for another few hours, then another slew of random ip's would attack. When a bunch of random ip's all attack around the same time, it's most likely a botnet. As long as an attacker's ssh request isn't 'refused' they will keep trying. If you block all ip's, they attack for a few attempts and give up since they get a 'connection refused' message.

Sometimes, people will change the ssh port to something random. This stops 99% of attacks from happening since they all target 22.
 
Old 09-26-2008, 01:53 PM   #7
Excalibre
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by CRC123 View Post
Sometimes, people will change the ssh port to something random. This stops 99% of attacks from happening since they all target 22.
Right -- I deliberately left sshd listening to 22 today just to see. Normally I use 443 since our firewall at work blocks outgoing traffic to any port but 80 or 443.
 
Old 09-26-2008, 01:59 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by CRC123 View Post
There are two values in 'sshd_conf' that can me modified to produce more log output:
Code:
LogLevel [QUIET|FATAL|ERROR|INFO|VERBOSE|DEBUG|DEBUG1|DEBUG2|DEBUG3]
# and
SyslogFacility [DAEMON|USER|AUTH|LOCAL0|LOCAL1|LOCAL2|LOCAL3|LOCAL4|LOCAL5|LOCAL6|LOCAL7]
Only LogLevel affects what is logged, SyslogFacility logs WHERE it is logged. Info should show failed attempts, but Verbose will give even more. Do not use Debug+ on production, as this actually logs some sensitive information.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ssh Logs alpha_hack Slackware 1 12-21-2007 10:41 AM
ssh logs? dsids Linux - Security 3 04-05-2006 01:15 PM
SSH logs in suse10 onjoo SUSE / openSUSE 6 11-08-2005 01:34 PM
i want to make more bigger logs rhoyerboat Linux - Security 1 08-06-2005 11:34 AM
Howto know each ssh users logs in at least every 24hrs gian2oo1 Slackware 5 04-20-2005 12:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration