LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Keeping A (log)Watchful Eye on Your VPS With logwatch

Your logs are an invaluable source of information about what’s going on inside your system and can alert you to security issues, service issues, and hardware problems.Β  But you are only aware of what they’re trying to tell you if you actually read them.Β  It would be a burdensome chore to login to each system every day and manually view the logs.Β  Fortunately, you can automate this task with the logwatch tool, which is a customizable, pluggable log monitoring system.

Read more to continue…

To install logwatch on Debian-based systems:

Β  Β  apt-get install logwatch

On CentOS-based systems:

 Β  yum -y install logwatch 

Just running logwatch out of the box gives us some great info:

Β  Β  $ logwatch
 ################### Logwatch 7.4.0 (03/01/11) #################### 
Β  Β  Β  Β  Processing Initiated: Tue AprΒ  7 22:30:28 2020
Β  Β  Β  Β  Date Range Processed: yesterday
Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  ( 2020-Apr-06 )
Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Period is day.
Β  Β  Β  Β  Detail Level of Output: 0
Β  Β  Β  Β  Type of Output/Format: stdout / text
Β  Β  Β  Β  Logfiles for Host: myserver.example.com
 ################################################################## 
 --------------------- SSHD Begin ------------------------ 
 Illegal users from:
Β  Β  undef: 62 times
Β  Β  51.91.140.218: 5 times
Β  Β  76.72.169.18 (egh4.com): 3 times
Β  Β  88.146.200.8: 6 times
Β  Β  92.63.194.7: 2 times
Β  Β  92.63.194.104: 1 time
Β  Β  92.63.194.105: 2 times
Β  Β  92.63.194.106: 1 time
Β  Β  92.63.194.107: 1 time
Β  Β  92.63.194.108: 2 times
Β  Β  93.174.93.10 (storedatatips.com): 2 times
Β  Β  93.235.99.248 (p5DEB63F8.dip0.t-ipconnect.de): 2 times
Β  Β  144.217.207.15 (ip15.ip-144-217-207.net): 1 time
Β  Β  176.37.60.16 (host-176-37-60-16.la.net.ua): 2 times
Β  Β  177.161.47.151 (177-161-47-151.user.vivozap.com.br): 35 times
Β  Β  179.106.64.134 (179-106-64-134.hnnet.com.br): 1 time
Β  Β  185.234.218.68: 1 time
Β  Β  193.142.146.21: 64 times
Β  Β  195.231.8.141 (host141-8-231-195.serverdedicati.aruba.it): 4 times
Β  Β  203.185.4.41 (mail.belfry.com.hk): 13 times
Β  Β  205.185.120.163 (.): 5 times
Β  Β  212.85.80.247 (h-80-247.A165.priv.bahnhof.se): 2 times

 Received disconnect:
Β  Β  11: Bye Bye [preauth] : 435 Time(s)
Β  Β  11: Normal Shutdown, Thank you for playing [preauth] : 22 Time(s)
 ---------------------- SSHD End ------------------------- 

 --------------------- Disk Space Begin ------------------------ 
 FilesystemΒ  Β  Β  SizeΒ  Used Avail Use% Mounted on
 devtmpfsΒ  Β  Β  Β  486M Β  Β  0Β  486M Β  0% /dev
 /dev/vda1Β  Β  Β  Β  25GΒ  1.6G Β  22G Β  7% /
 ---------------------- Disk Space End ------------------------- 

 ###################### Logwatch End ######################### 

Here we can see numerous attempted logins (probably because ssh was still running on port 22) as well as the status of our disk space.Β  This is an example of detail on the ‘Low’ setting.Β  If we turned on the ‘High’ output of detail, we’d be able to see exactly which user tried to login.

One of the nice things about logwatch is that as you add services (email, httpd, etc.) logwatch will detect this and add sections to your reports with pertinent information.

It’s easy to configure logwatch to mail reports to you daily, which allows a quick review.

Modify /etc/logwatch/conf/logwatch.conf and add the following line:

Β  Β  MailTo = <your email>
Β  Β  Output = email
Β  Β  Detail = High

By default, both Debian and CentOS create cron jobs to run logwatch nightly (in /etc/cron.daily) so you should begin receiving reports nightly.

 

No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

    Your email address will not be published. Required fields are marked *