• TechOps

    Need clarity?
    Chat with our experts now

    • Web Hosting SupportWeb Hosting Support
    • Helpdesk Support

      Skilled and professional 24/7 helpdesk support

    • Product Support

      Boost your product support with our expertise

    • Managed ServicesManaged Services
    • Server Management

      Don't let server issues slow you down. Let us manage them for you

    • Server Monitoring

      Safeguard your server health with our comprehensive monitoring solutions

    • Staff AugmentationStaff Augmentation
    • Hire an Admin

      Transform your business operations with our expert administrative support

    • Hire a Team

      Augment your workforce with highly skilled professional from our diverse talent pool

  • CloudOps

    Confused?
    Discuss with our sales team now.

    • Author ProfileAWS
      Well Architected Review
    • Author ProfileFinOps As a Service

      FinOps As a Service

    • Migrate

      Upgrade the journey: Migrate & Modernize seamlessly

    • Modernize

      Effortless CloudOps mastery for seamless cloud management

    • Optimize

      Efficient CloudOps: Boosting performance through optimization

    • Manage

      Simplify compliance complexities with our dedicated service

  • DevOps

    How Supportsages
    is creating an
    impact?

    View Casestudies
    • Author Profile24/7 DevOps As a Service

      Round-the-clock DevOps for uninterrupted efficiency

    • Author ProfileCI/CD Pipeline

      Automated CI/CD pipeline for seamless deployments

    • Author ProfileInfrastructure As a Code

      Crafting infrastructure with ingenious code

    • Author ProfileDevSecOps

      Integrated security in continuous DevOps practices

    • Author ProfileHire DevOps Engineers

      Level up your team with DevOps visionaries

    • Author ProfileConsulting Services

      Navigate success with expert DevOps consulting

  • SecOps

    Expert SecOps Services
    for any Scale

    • Author ProfileVAPT

      Vulnerability Assessment and Penetration Testing

    • Author ProfileSource Code Review

      Ensuring source code security and safe practices to reduce risks

    • Author ProfileSecurity Consultation

      On demand services for improving server security

    • Author ProfileSystem Hardening

      Reduced vulnerability and proactive protection

    • Author ProfileManaged SOC

      Monitors and maintains system security. Quick response on incidents

    • Author ProfileCompliance as a Service

      Regulatory compliance, reduced risk

  • Insights

    Explore our latest
    insights and resources

    Blog

    Explore our latest articles and insights

    Case Studies

    Read about our client success stories

  • Contact Us

  • About
  • Certifications
  • Life at Supportsages
  • Events
  • Contact
  • Careers
  • Blog

  • Dedicated Support Team
  • Quasi-dedicated Support Team
  • Hire a DevOps Engineer
  • Hire a Billing Support Staff
  • Per-ticket Support Plan
  • Managed Services

  • Microsoft Azure Expert
  • AWS Cloud Expert
  • Hire a developer
SS

SupportSages

Bites of wisdom @ work


Copyright © 2008 - 2026 SupportSages Pvt Ltd. All Rights Reserved.
Privacy PolicyLegal TermsData ProtectionCookie Policy

Monitor changes made to a file using auditd

Ruben Roy

  • 4 min read
Monitor changes made to a file using auditd

Generating audio, please wait...

Modern Linux kernel comes with auditd daemon. It is responsible for writing audit records to the disk. During startup, the rules in /etc/audit.rules are read by this daemon. You can open /etc/audit.rules file and make changes such as setup audit file log location and other option. The default file is good enough to get started with auditd.

ausearch is a simple command line tool used to search the audit daemon log files based on events and different search criteria such as event identifier, key identifier, CPU architecture, command name, hostname, group name or group ID, syscall, messages and beyond. It also accepts raw data from stdin.

By default, ausearch queries the /var/log/audit/audit.log file, which you can view just like any other text file.

In order to use audit facility you need to use following utilities

auditctl    –   A command to assist controlling the kernels audit system. You can get status, and add or delete rules into kernel audit system. Setting a watch on a file is accomplished using this command

ausearch –   A command that can query the audit daemon logs based for events based on different search criteria.

aureport   –  A tool that produces summary reports of the audit system logs.

Step1: Install audit package

The audit package contains the user space utilities for storing and searching the audit records generate by the audit subsystem in the Linux 2.6 kernel.

root@sage16:/home/jackson# sudo apt-get update
root@sage16:/home/jackson# sudo apt-get install auditd
Reading package lists... Done
Building dependency tree      
Reading state information... Done

Now start service:

root@sage16:/home/jackson# /etc/init.d/auditd start 
[ ok ] Starting auditd (via systemctl): auditd.service.

How do I set a watch on a file for auditing?

Let us say you would like to audit a /etc/passwd file. You need to type command as follows:

#  auditctl -w /etc/passwd -p war -k password-file

Where,

-w /etc/passwd –   Insert a watch for the file system object at given path i.e. watch file called /etc/passwd

-p war –  Set permissions filter for a file system watch. It can be r for read, w for write, x for execute, a for append.

-k password-file – Set a filter key on a /etc/passwd file (watch). The password-file is a filterkey (string of text that can be up to 31 bytes long). It can uniquely identify the audit records produced by the watch. You need  to use password-file string or phrase while searching audit logs.

For Example let us see how do we find out who changed or accessed a file /etc/passwd?

Use ausearch command as follows:

# ausearch -f /etc/passwd 
OR 
# ausearch -f /etc/passwd | less 
OR 
# ausearch -f /etc/passwd -i | less

For example I have created the file and set a watchlog as  shown below

#  sudo auditctl -w /home/jackson/audit_test -p war

Now I am using ausearch command find out who changed or accessed a file

ausearch -f /home/jackson/audit_test

Please see the output as follows.

time->Sat May 18 18:36:57 2019 
type=PROCTITLE msg=audit(1558184817.050:210): proctitle="gedit" 
type=PATH msg=audit(1558184817.050:210): item=0 name="/home/jackson/audit_test" inode=13336667 dev=00:35 mode=0100664 ouid=10231 ogid=10231 rdev=00:00 nametype=NORMAL cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 
type=CWD msg=audit(1558184817.050:210): cwd="/home/jackson" 
type=SYSCALL msg=audit(1558184817.050:210): arch=c000003e syscall=2 success=yes exit=20 a0=1b57bc0 a1=0 a2=0 a3=aaaaaaaaaaaaaaab items=1 ppid=1568 pid=4084 auid=4294967295 uid=10231 gid=10231 euid=10231 suid=10231 fsuid=10231 egid=10231 sgid=10231 fsgid=10231 tty=(none) ses=4294967295 comm="pool" exe="/usr/bin/gedit" key=(null)

Find User Activity in Auditd Log File, Please note that the -ua is used to pass a username.

# ausearch -ua jackson 

OR 

# ausearch -ua ruben -i

Please see the output added below. From the results, we can check which file has been edited by ‘jackson’

---- time->Sat May 18 18:59:45 2019

type=USER_END msg=audit(1558186185.996:50): pid=10976 uid=10221 auid=4294967295 ses=4294967295 msg='op=PAM:session_close acct="root" exe="/bin/su" hostname=? addr=? terminal=/dev/pts/25 res=success'

----

time->Sat May 18 18:59:45 2019

type=CRED_DISP msg=audit(1558186185.996:51): pid=10976 uid=10221 auid=4294967295 ses=4294967295 msg='op=PAM:setcred acct="root" exe="/bin/su" hostname=? addr=? terminal=/dev/pts/25 res=success'

Conclusion

So in this blog we discussed about the auditctl command  that assist controlling the kernels audit system. You can get status, and add or delete rules into kernel audit system. Setting a watch on a file is accomplished using this command. Also, using ausearch command we  can query the audit daemon logs based for events based on different search criteria.

server monitoring

  • Security
  • Server Monitoring

Looking for AWS Experts?

We provide top-of-the-line custom AWS setup services tailored to your needs.

Monitor changes made to a file using auditd

Applying Kernel Patch Without Rebooting

Applying Kernel Patch Without Rebooting
  • Server Monitoring
logo

Best practices to reduce customer complaints in shared hosting support

Best practices to reduce customer complaints in shared hosting support
  • Customer Care
logo

To check which all ports are listening (Introducing Four Linux Commands)

To check which all ports are listening (Introducing Four Linux Commands)
  • Linux
logo

Why should you think of outsourcing backup management?

Why should you think of outsourcing backup management?
  • Backup management
logo

Posts by Ruben Roy

Ruben Roy