AUDITCTL(8)
πΈ NAME πΈ
okay bestie, welcome to AUDITCTL(8) from the System Administration Utilities corner of the manual β the vibe is literally just:
auditctl β a utility to assist controlling the kernel's audit system π
π¦ SYNOPSIS π¦
auditctl [options]
β¨ DESCRIPTION β¨
So the auditctl program is the girl who configures kernel options related to auditing, checks the status of that configuration, and loads discretionary audit rules. Three jobs, one icon. π
π CONFIGURATION OPTIONS π
-bbacklog β sets the max number (the limit, bestie) of outstanding audit buffers allowed. Kernel Default is64. And if all the buffers are full? The kernel consults the failure flag for what to do next. no cap.--backlog_wait_timewait_time β sets how long the kernel waits (Kernel Default60*HZ) once the backlog limit has been reached, before it queues up even more audit events to be transferred toauditd. The number has to be greater than or equal to zero, and less than 10 times the default value. periodt.--reset_backlog_wait_time_actualβ resets the actual backlog wait time counter that the status command shows you.-cβ keeps loading rules even when there's an error. It summarizes the results of loading the rules. Heads up though: the exit code will not be success if any rule fails to load. π-Dβ deletes all rules and watches. This can take a key option (-k), too.-e [0..2]β sets the enabled flag. Pass0and you can temporarily disable auditing. Pass1as the argument and it enables auditing. And to lock the audit configuration so nobody can change it, pass a2as the argument. Locking the configuration is meant to be the last command inaudit.rulesfor anyone who wants this feature active. Any attempt to change the configuration in this mode will be audited and denied. The only way to change the configuration after that is rebooting the machine. it's giving permanent. π-f [0..2]β sets the failure mode:0=silent1=printk2=panic. This is where you decide how you want the kernel to handle critical errors. Example conditions where this mode may have an effect include: transmission errors to userspace audit daemon, backlog limit exceeded, out of kernel memory, and rate limit exceeded. The default value is1. Secure environments will probably want to set this to2. dramatic but valid.-h,--helpβ Help π«Ά-iβ when given by itself, it ignores errors when reading rules from a file. This causesauditctlto always return a success exit code. But if you pass it as an argument to-s, then it gives you an interpretation of the numbers into human readable words, if possible.--loginuid-immutableβ this one tells the kernel to make loginuids unchangeable once they're set. Changing loginuids requiresCAP_AUDIT_CONTROL, so it's not something unprivileged users can just do. Setting this makes loginuid tamper-proof, but it can cause some problems in certain kinds of containers. tradeoffs, always.-qmount-point,subtree β if you have an existing directory watch and you bind or move mount another subtree into the watched subtree, you need to tell the kernel to make the subtree being mounted equivalent to the directory being watched. If the subtree is already mounted at the time the directory watch is issued, the subtree is automatically tagged for watching. Please note the comma separating the two values β omitting it will cause errors. β οΈ-rrate β sets the limit in messages/sec (0=none). If this rate is non-zero and gets exceeded, the failure flag is consulted by the kernel for action. The default value is0.--reset-lostβ resets the lost record counter that the status command shows you.-Rfile β read and executeauditctlcommands from a file. The commands are executed line-by-line, in the order they appear in the file. The file must be owned by root and not readable by other users, or else it will be rejected. Empty lines are skipped. Lines starting with the#character are treated as comment lines. Each line is executed as if it was provided toauditctlas command line arguments. And becauseauditctlis the one reading the file and not a shell such asbash, do not escape special shell characters. See the EXAMPLES section for an example. π--signalsignal β sends a signal to the audit daemon. You must have privileges to do this. Supported signals areTERM,HUP,USR1,USR2,CONTand the user friendly versionsstop,reload,rotate,resume,state. pick your fighter.-tβ trims the subtrees after a mount command.
π STATUS OPTIONS π
-lβ lists all rules, 1 per line. Two more options may be given to this command. You can give either a key option (-k) to list rules that match a key, or a (-i) to havea0througha3interpreted to help determine the syscall argument values are correct.-mtext β sends a user space message into the audit system. This can only be done if you have theCAP_AUDIT_WRITEcapability (normally the root user has this). The resulting event will be theUSERtype.-sβ reports the kernel's audit subsystem status. It tells you the in-kernel values that can be set by the-e,-f,-r, and-boptions. Thepidvalue is the process number of the audit daemon β and note that apidof0indicates that the audit daemon is not running. π Thelostentry tells you how many event records have been discarded due to the kernel audit queue overflowing. Thebacklogfield tells how many event records are currently queued, waiting forauditdto read them. This option can be followed by the-ito get a couple fields interpreted.-vβ prints the version ofauditctl.
π₯ RULE OPTIONS π₯
-a [list,action|action,list]β appends a rule to the end of list with action. Please note the comma separating the two values β omitting it will cause errors. The fields may be in either order, so it could belist,actionoraction,list. Here's the valid list names:taskβ adds a rule to the per task list. This rule list is used only at the time a task is created β whenfork()orclone()are called by the parent task. When you use this list, you should only use fields that are known at task creation time, such as theuid,gid, etc.exitβ adds a rule to the syscall exit list. This list is used upon exit from a system call to determine if an audit event should be created.userβ adds a rule to the user message filter list. This list is used by the kernel to filter events originating in user space before relaying them to the audit daemon. It should be noted that the only fields that are valid are:uid,auid,gid,pid,subj_user,subj_role,subj_type,subj_sen,subj_clr,msgtype, and executable name. All other fields will be treated as non-matching. And you should understand that any event originating from user space from a process that hasCAP_AUDIT_WRITEwill be recorded into the audit trail. Which means the most likely use for this filter is with rules that have an action ofnever, since nothing has to be done to allow events to be recorded.excludeβ adds a rule to the event type exclusion filter list. This list filters events that you do not want to see. For example, if you don't want to see anyavcmessages, you'd use this list to record that. Events can be excluded by process ID, user ID, group ID, login user ID, message type, subject context, or executable name. The action is ignored and uses its default of"never".filesystemβ adds a rule that will be applied to a whole filesystem. The filesystem must be identified with afstypefield. Normally this filter is used to exclude any events for a whole filesystem such astracefsordebugfs.io_uringβ adds a rule to theio_uringsyscall filter. Rules against this filter specify the syscall operation using the-Ssyscall notion explained below. You can add a key field to the rule so that it may be grouped with other rules watching the same underlying syscall.
And here are the valid actions for the rule:
neverβ no audit records will be generated. This can be used to suppress event generation. In general, you want suppressions at the top of the list instead of the bottom. This is because the event triggers on the first matching rule. iykyk.alwaysβ allocates an audit context, always fills it in at syscall entry time, and always writes out a record at syscall exit time.
-Alist,action β adds a rule to the beginning of list with action.-C [f=f | f!=f]β builds an inter-field comparison rule: field, operation, field. You may pass multiple comparisons on a single command line β each one must start with-C. Each inter-field equation is anded with each other, as well as with equations starting with-F, to trigger an audit record. There are 2 operators supported β equal, and not equal. The valid fields are:
auid, uid, euid, suid, fsuid, obj_uid; and gid, egid, sgid, fsgid, obj_gid
The two groups of uid and gid cannot be mixed. But any comparison within the group can be made. The obj_uid/obj_gid fields are collected from the object of the event, such as a file or directory. ποΈ
-dlist,action β deletes a rule from list with action. The rule is deleted only if it exactly matches syscall name(s) and every field name and value.-F [n=v | n!=v | n<v | n>v | n<=v | n>=v | n&v | n&=v]β bestie, this is where you build a rule field: name, operation, value. You can stack up to 64 fields on a single command line β¨, and every single one of them has to start with-F. Each field equation gets anded with every other one (and also with any equations starting with-C) to trigger an audit record. There are 8 operators supported β equal, not equal, less than, greater than, less than or equal, greater than or equal, bit mask, and bit test, respectively π«Ά. Bit test will "and" the values and then check that they're equal; bit mask just "ands" the values. Fields that take a user ID may instead have the user's name β the program will convert the name to user ID, and the same is true of group names π . Valid fields are:a0,a1,a2,a3β Respectively, the first 4 arguments to a syscall. Note that string arguments are not supported. This is because the kernel is passed a pointer to the string, and triggering on a pointer address value is not likely to work π. So when you use this, you should only use it on numeric values. This is most likely to be used on platforms that multiplex socket or IPC operations.archβ The CPU architecture of the syscall. The arch can be found doing'uname -m'. If you do not know the arch of your machine but you want to use the 32 bit syscall table and your machine supports 32 bit, you can also useb32for the arch. The same applies to the 64 bit syscall table β you can useb64. That way you can write rules that are somewhat arch independent, because the family type will be auto detected π«. However, syscalls can be arch specific and what is available onx86_64may not be available onppc. Thearchdirective should precede the-Soption so thatauditctlknows which internal table to use to look up the syscall numbers.auidβ The original ID the user logged in with. It's an abbreviation of audit uid. Sometimes it's referred to asloginuid. Either the user account text or number may be used.devmajorβ Device Major Numberdevminorβ Device Minor Numberdirβ Full Path of Directory to watch. This will place a recursive watch on the directory and its whole subtree π. It can only be used on exit list. See"-w".egidβ Effective Group ID. May be numeric or the groups name.euidβ Effective User ID. May be numeric or the user account name.exeβ Absolute path to application that while executing this rule will apply to. It supports=and!=operators. Note that you can only use this once for each rule.exitβ Exit value from a syscall. If the exit code is anerrno, you may use the text representation, too.fsgidβ Filesystem Group ID. May be numeric or the groups name.fstypeβ File system type. This is used with the filesystem rule list. The only values supported arecgroup,cgroup2,debugfsandtracefs.fsuidβ Filesystem User ID. May be numeric or the user account name.filetypeβ The target file's type. Can be eitherfile,dir,socket,link,character,block, orfifo.gidβ Group ID. May be numeric or the groups name.inodeβ Inode Numberkeyβ Set a filter key on an audit rule. The filter key is an arbitrary string of text that can be up to 31 bytes long. It can uniquely identify the audit records produced by a rule π. Typical use is for when you have several rules that together satisfy a security requirement. The key value can be searched on withausearchso that no matter which rule triggered the event, you can find its results. The key can also be used on delete all (-D) and list rules (-l) to select rules with a specific key. You may have more than one key on a rule if you want to be able to search logged events in multiple ways, or if you have anauditdplugin that uses a key to aid its analysis.msgtypeβ This is used to match the event's record type. It should only be used on the exclude or user filter lists.obj_uidβ Object's UIDobj_gidβ Object's GIDobj_userβ Resource's SE Linux Userobj_roleβ Resource's SE Linux Roleobj_typeβ Resource's SE Linux Typeobj_lev_lowβ Resource's SE Linux Low Levelobj_lev_highβ Resource's SE Linux High Levelpathβ Insert a watch for the file system object at path. You cannot insert a watch to the top level directory. This is prohibited by the kernel. Wildcards are not supported either and will generate a warning π. The way that watches work is by tracking the inode internally. This can only be used on exit list.permβ Permission filter for file operations. Supply the access type that a file system watch will trigger on.r=read,w=write,x=execute,a=attribute change. These permissions are not the standard file permissions, but rather the kind of syscall that would do this kind of thing. The read & write syscalls are omitted from this set since they would overwhelm the logs π. But rather for reads or writes, the open flags are looked at to see what permission was requested. Thepermfield can only be used on exit list. You can use this without specifying a syscall and the kernel will select the syscalls that satisfy the access permissions being requested. This also requires supplying anarchparameter before thepermfield β this way the kernel can better determine what syscalls are needed. Not supplying anarchwill result in all system calls being subject to audit. This will lower system performance.persβ OS Personality Numberpidβ Process IDppidβ Parent's Process IDsaddr_famβ Address family number as found in/usr/include/bits/socket.h. For example, IPv4 would be2and IPv6 would be10.sessionidβ User's login session IDsubj_userβ Program's SE Linux Usersubj_roleβ Program's SE Linux Rolesubj_typeβ Program's SE Linux Typesubj_senβ Program's SE Linux Sensitivitysubj_clrβ Program's SE Linux Clearancesgidβ Saved Group ID. Seegetresgid(2)man page.successβ If the exit value is>= 0this is true/yes, otherwise it's false/no. When writing a rule, use a1for true/yes and a0for false/no.suidβ Saved User ID. Seegetresuid(2)man page.uidβ User ID. May be numeric or the user account name.
-k keyβ Set a filter key on an audit rule. This is deprecated when used with watches. Convert any watches to the syscall form of rules. It is still valid for use with deleting or listing rules β¨.-p [r|w|x|a]β Describe the permission access type that a file system watch will trigger on. This is deprecated. Convert watches to the syscall form, bestie, fr fr.-S [Syscall name or number|all]β Any syscall name or number may be used. The word'all'may also be used. If the given syscall is made by a program, then start an audit record π. If a field rule is given and no syscall is specified, it will default to all syscalls. You may also specify multiple syscalls in the same rule by using multiple-Soptions in the same rule β doing so improves performance since fewer rules need to be evaluated π . Alternatively, you may pass a comma separated list of syscall names. If you are on a bi-arch system, likex86_64, you should be aware thatauditctlsimply takes the text, looks it up for the native arch (in this caseb64) and sends that rule to the kernel. If there are no additionalarchdirectives, IT WILL APPLY TO BOTH 32 & 64 BIT SYSCALLS. This can have undesirable effects since there is no guarantee that any syscall has the same number on both 32 and 64 bit interfaces π. You will likely want to control this and write 2 rules, one with arch equal tob32and one withb64, to make sure the kernel finds the events that you intend. See thearchfield discussion for more info.-w pathβ Place a watch on path. If the path is a file, it's almost the same as using the-F pathoption on a syscall rule. If the watch is on a directory, it's almost the same as using the-F diroption on a syscall rule. The-wform of writing watches is for backwards compatibility and is deprecated due to poor system performance. Convert watches of this form to the syscall based form, bestie π«Ά. The only valid options when using a watch are the-pand-k.-W pathβ Remove a watch for the file system object at path. The rule must match exactly. See-ddiscussion for more info.
π PERFORMANCE TIPS (bestie listen up, this part is important)
Syscall rules get evaluated for each syscall for every program. If you have 10 syscall rules, every program on your system will delay during a syscall while the audit system evaluates each rule. Too many syscall rules will hurt performance. Try to combine as many as you can whenever the filter, action, key, and fields are identical. For example:
auditctl -a always,exit -F arch=b64 -S openat -F success=0
auditctl -a always,exit -F arch=b64 -S truncate -F success=0
could be re-written as one rule:
auditctl -a always,exit -F arch=b64 -S openat -S truncate -F success=0
Also, try to use file system auditing wherever practical. This improves performance. For example, if you were wanting to capture all failed opens & truncates like above, but were only concerned about files in /etc and didn't care about /usr or /sbin, its possible to use this rule:
auditctl -a always,exit -F arch=b64 -S openat,truncate -F dir=/etc -F success=0
This will be higher performance since the kernel will not evaluate it each and every syscall. It will be handled by the filesystem auditing code and only checked on filesystem related syscalls.
no cap bestie, one rule per syscall is the vibe killer π combine when the filter, action, key, and fields all match β the kernel will thank you π«Ά
β¨ EXAMPLES β¨ (the fun part, fr fr)
To see all syscalls made by a specific program:
# By pid:
auditctl -a always,exit -S all -F pid=1005
# By executable path
auditctl -a always,exit -S all -F exe=/usr/bin/ls
To see files opened by a specific user:
auditctl -a always,exit -S openat -F auid=510
To see unsuccessful openat calls:
auditctl -a always,exit -S openat -F success=0
To watch a file for changes (2 ways to express):
auditctl -w /etc/shadow -p wa # Note this slows the system
auditctl -a always,exit -F arch=b64 -F path=/etc/shadow -F perm=wa
To recursively watch a directory for changes (2 ways to express):
auditctl -w /etc/ -p wa # Note this slows the system
auditctl -a always,exit -F arch=b64 -F dir=/etc/ -F perm=wa
To see if an admin is accessing other user's files:
auditctl -a always,exit -F dir=/home/ -F uid=0 -C auid!=obj_uid
This is an example rules file:
# Remove all existing rules
-D
# Never record sudo invocations
-A exclude,always -F exe=/usr/bin/sudo
πΈ DISABLED BY DEFAULT (the plot twist nobody expects)
On many systems auditd is configured to install an -a never,task rule by default. This rule causes every new process to skip all audit rule processing. This is usually done to avoid a small performance overhead imposed by syscall auditing. If you want to use auditd, you need to remove that rule by deleting 10-no-audit.rules and adding 10-base-config.rules to the audit rules directory.
If you have defined audit rules that are not matching when they should, check auditctl -l to make sure there is no never,task rule there.
the way thatnever,taskwill just silently eat your whole rule setβ¦ π not me losing my mind debugging rules that were literally never running π checkauditctl -lbestie, always.
π FILES π
/etc/audit/audit.rules/etc/audit/audit-stop.rules
π¦ SEE ALSO π¦
audit.rules(7), ausearch(8), aureport(8), auditd(8).
π AUTHOR π
Steve Grubb
and that's the whole page bestie, you ate π
this icon of a manpage is from the Red Hat fam, sitting at Sep 2023, and it's the AUDITCTL(8) entry β go forth and audit responsibly, mwah π«Άβ¨πΈ
π¦ where this page comes from
- arch rolling: audit 4.2.1-1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- centos-stream 10: audit-rules 4.2.1-3.el10 Β· GPL-2.0-or-later
- fedora 43: audit-rules 4.2.1-1.fc43 Β· GPL-2.0-or-later
- fedora 44: audit-rules 4.2.1-1.fc44 Β· GPL-2.0-or-later
- nixpkgs unstable: audit 4.2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms