---
title: Verify Permissions of Log Files Are 0644 or More Restrictive
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > Verify Permissions of Log Files Are
  0644 or More Restrictive
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Verify Permissions of Log Files Are 0644 or More Restrictive
 
## Description{% #description %}

Every file under `/var/log`, in its subdirectories too, must not be executable or writable by its group or by others: its mode must be `0644` or more restrictive. The utmp files `lastlog`, `wtmp`, `btmp` and their rotated copies, and `README`, may be group writable and are left out. To find the files that fail, run:

```gdscript3
$ sudo find -L /var/log -type f -perm /0133 ! -name lastlog ! -name 'lastlog.*' ! -name '[bw]tmp' ! -name '[bw]tmp[.-]*' ! -name README
```

and remove the excess permissions of each file it prints with `chmod u-x,g-wx,o-wx`.

## Rationale{% #rationale %}

Log files record the activity of the system and its users. A log file that others can write can be altered to hide that activity.

## Remediation{% #remediation %}

### Shell script{% #shell-script %}

The following script can be run on the host to remediate the issue.

```bash
#!/bin/bash

find -P /var/log/  -perm /u+xs,g+xws,o+xwt ! -name '[bw]tmp' ! -name '[bw]tmp[.-]*' ! -name 'lastlog' ! -name 'lastlog[.]*' ! -name 'README' -type f -regextype posix-extended -regex '.*' -exec chmod u-xs,g-xws,o-xwt {} \;
```

### Ansible playbook{% #ansible-playbook %}

The following playbook can be run with Ansible to remediate the issue.

```gdscript3
- name: Find /var/log/ file(s) recursively
  ansible.builtin.command: find -P /var/log/  -perm /u+xs,g+xws,o+xwt ! -name "[bw]tmp"
    ! -name "[bw]tmp[.-]*" ! -name "lastlog" ! -name "lastlog[.]*" ! -name "README"
    -type f -regextype posix-extended -regex ".*"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  tags:
  - configure_strategy
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
  - permissions_local_var_log_0644

- name: Set permissions for /var/log/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-xs,g-xws,o-xwt
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  tags:
  - configure_strategy
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
  - permissions_local_var_log_0644
```
