Linux var log btmp

Одминский блог

Полез тут кой что подкрутить на своем простеньком хостинге, который я держу в Reg.ru под парсинг выдачи Яндекса и Wordstat.Yandex. Хостинг у Reg.ru надо заметить крайне надежный, в плане стабильности, и при этом весьма экономичный.

Держал бы у них даже некоторые свои проекты, если бы не мракобесие, творящееся в тырнетах, так что хостить проекты как то надежнее в бургонете.
Так вот, держу у них легкий Xen VPS крутящийся под Cent OS. Все удовольствие 360 рублей в месяц, за 512Mb RAM & 8Gb HDD.

И тут зачем то глянул занятость диска, а свободного пространства осталось всего 5%, при том что система от силы на гиг тянет.

Естественно первым делом в логи, и обнаруживаю занятный файл /var/log/btmp который и тянет на 5 гигов. Естественно что первым делом я его пнул через tail, после чего у меня заглючила консоль, так как листинг файла вывалил крякозябры, намекающие на то, что файл содержит не текстовую информацию, а бинарную.

Сам файл представляет из себя фиксацию неудачных попыток логина, так что по большому счету там преимущественно толкутся записи о брутфорс атаках на сервер.

Если просмотреть вывод файлы, через команду:
# last -f /var/log/btmp
то увидим что то типо такого:

test ssh:notty 222.85.90.245 Thu Feb 6 18:10 – 18:10 (00:00)
test ssh:notty 222.85.90.245 Thu Feb 6 18:09 – 18:10 (00:00)
test ssh:notty 222.85.90.245 Thu Feb 6 18:09 – 18:09 (00:00)
root ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:09 (00:02)
root ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)
root ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)
root ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)
mysql ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)
mysql ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)
mysql ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)
mysql ssh:notty 98.158.29.93 Thu Feb 6 18:07 – 18:07 (00:00)

то есть на лицо запалившиеся голубцы и логины под которыми они и пытались проломиться.

Читайте также:  Linux mint cinnamon with kde

Также можно использовать команду
# utmpdump /var/log/btmp
дающую несколько более полную информацию и более попсовый листинг

Теоретически, можно настроить механизм, чтобы любители брута отправлялись,после нескольких неудачных попытов, сразу же в бан через iptables, и тогда надо будет настраивать ротацию лога, в /etc/logrotate.conf подправив имеющееся выражение на это:
/var/log/btmp monthly
minsize 1M
create 0600 root utmp
rotate 1
>

Поскольку запариватся мне с ним не хотелось, то я его обнулил естественным путем
# cat /dev/null > /var/log/btmp
после чего перевесил демона sshd на пятизначный порт > 1024, что естественно выключило все попытки брута, о чем я как то давно уже писал.

*** Хозяйке на заметку:
В системе имеются еще два файла:
/var/log/wtmp в который пишутся все логины в систему
/var/run/utmp который показывает активные на данный момент сессии
синтаксис просмотра тот же самый, через команду utmpdump

Источник

How to View and Configure Linux System Logs on Ubuntu 20.04

This tutorial explains the basic administration of a Linux server through system logs. A system log is a file that contains information about the events that happened on the system during runtime.

In this article, you will learn the following Linux logging basics:

  • Where the Linux log files are stored, how are they formatted, and how to read them.
  • How to read the most important logs (such as syslog ).
  • How to configure the Ubuntu syslog daemon.
  • What Linux log rotation is all about and how to use the logrotate utility.

Prerequisites

Before proceeding with the rest of this tutorial, ensure that you have a basic knowledge of working with the Linux command line. While many of the concepts discussed in this article are general applicable to all Linux distributions, we’ll be demonstrating them in Ubuntu only so ensure to set up an Ubuntu 20.04 server that includes a non-root user with sudo access.

🔭 Want to centralize and monitor your Linux logs?

Head over to Logtail and start ingesting your logs in 5 minutes.

Step 1 — Finding Linux system logs

All Ubuntu system logs are stored in the /var/log directory. Change into this directory in the terminal using the command below:

Читайте также:  How to scroll linux terminal

You can view the contents of this directory by issuing the following command:

You should see a similar output to the following:

alternatives.log auth.log btmp cloud-init-output.log dmesg dpkg.log journal/ landscape/ private/ ubuntu-advantage-license-check.log ubuntu-advantage-timer.log unattended-upgrades/ apt/ bootstrap.log cloud-init.log dist-upgrade/ dmesg.0 faillog kern.log lastlog syslog ubuntu-advantage.log ufw.log wtmp 

Let’s look at a few of the essential system log files that may be present in the /var/log directory and what they contain:

  • /var/log/syslog : stores general information about any global activity in the system.
  • /var/log/auth.log : keeps track of all security-related actions (login, logout, or root user activity).
  • /var/log/kern.log : stores information about events originating from the Linux kernel.
  • /var/log/boot.log : stores system startup messages.
  • /var/log/dmesg : contains messages related to device drivers.
  • /var/log/faillog : keeps track of failed logins, which comes in handy when investigating attempted security breaches.

The /var/log directory is also used to store various application logs. For example, if your distribution is bundled with Apache or MySQL, or installed later, their log files will also be found here.

Step 2 — Viewing Linux log file contents

Log files contain a large amount of information that are useful for monitoring or analyzing activities performed by the system or a specific application. Therefore, a Linux server administrator must learn the art of reading and understanding the various messages present in log files to effectively diagnose or troubleshoot an issue.

Before we can read log files, we ought to know how they are formatted. Let’s review two basic approaches to log file formatting and storage: plain text and binary files.

Plaintext log files

These logs are plain text files with a standardized content format. Ubuntu uses a log template called RSYSLOG_TraditionalFileFormat . This log format consists of four main fields with a space delimiter:

  1. The timestamp indicates the time when a log entry was created in the format MMM dd HH:mm:ss (e.g. Sep 28 19:00:00 ). Notice that this format does not include a year.
  2. Hostname is the host or system that originally create the message.
  3. Application is the application that created the message.
  4. Message contains the actual details of an event.
Читайте также:  Keytool command not found linux

Let’s go ahead and review some log files in the plaintext format. Run the command below to print the contents of the /var/log/syslog file with the tail utility:

This outputs the last 10 lines of the file:

Mar 23 12:38:09 peter dbus-daemon[1757]: [session uid=1000 pid=1757] Activating via systemd: service name='org.freedesktop.Tracker1' unit='tracker-store.service' requested by ':1.1' (uid=1000 pid=1754 comm="/usr/libexec/tracker-miner-fs " label="unconfined") Mar 23 12:38:09 peter systemd[1743]: Starting Tracker metadata database store and lookup manager. Mar 23 12:38:09 peter dbus-daemon[1757]: [session uid=1000 pid=1757] Successfully activated service 'org.freedesktop.Tracker1' Mar 23 12:38:09 peter systemd[1743]: Started Tracker metadata database store and lookup manager. Mar 23 12:38:40 peter tracker-store[359847]: OK Mar 23 12:38:40 peter systemd[1743]: tracker-store.service: Succeeded. Mar 23 12:39:01 peter CRON[359873]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi) Mar 23 12:39:23 peter systemd[1]: Starting Clean php session files. Mar 23 12:39:23 peter systemd[1]: phpsessionclean.service: Succeeded. Mar 23 12:39:23 peter systemd[1]: Finished Clean php session files. 

You’ll notice that that each record in this file is formatted in the manner described earlier. For example, the last record has its timestamp as Mar 23 12:39:23, hostname as peter, application as systemd[1] and message as Finished Clean php session files.

If you want to view the entire log file, you can use the cat utility or any text editor such as nano or vim .

Binary log files

While plaintext is the dominant storage format for log files, you will also encounter binary log files that cannot be read with a normal text editor. The /var/log directory contains multiple binary files that are related to the user authorization:

  • /var/log/utmp : tracks users that are currently logged into the system.
  • /var/log/wtmp : tracks previously logged in users. It contains a past data from utmp .
  • /var/log/btmp : tracks failed login attempts.

For these binary logs, special command-line tools are used to display the relevant information in human-readable form. For example, to review the contents of the /var/log/utmp file, run the who utility with -H option (this option causes column labels to be printed in the output table):

Источник

Оцените статью
Adblock
detector