{
  "id": "CB-UBU-AUTH-029",
  "standard": "ubuntu",
  "version": "main",
  "url": "https://baselines.cirsec.org/b/ubuntu/CB-UBU-AUTH-029",
  "json": "https://baselines.cirsec.org/b/ubuntu/CB-UBU-AUTH-029.json",
  "yaml": "https://baselines.cirsec.org/b/ubuntu/CB-UBU-AUTH-029.yml",
  "profiles_effective": [
    "core",
    "server",
    "server-hardened",
    "desktop",
    "desktop-hardened"
  ],
  "license": "Text CC BY 4.0, code Apache-2.0",
  "attribution": "CIRSEC Baselines, https://baselines.cirsec.org",
  "control": {
    "id": "CB-UBU-AUTH-029",
    "title": "Keep user home directories and dot files private",
    "finding": {
      "title": "User home directories or startup files are readable or writable by others",
      "description": "Other users can read private files, or change a user's shell startup files to run commands as that user."
    },
    "status": "active",
    "profiles": [
      "core"
    ],
    "risk": {
      "severity": "medium"
    },
    "assessment": "automated",
    "tags": [
      "accounts",
      "home",
      "permissions"
    ],
    "description": "For every interactive account (UID 1000 or above with a login shell):\n\n- the home directory exists, belongs to the user and has mode `750` or stricter;\n- files and directories whose name starts with a dot directly in the home (`.bashrc`,\n  `.profile`, `.ssh`...) belong to the user and are not writable by group or others;\n- `.netrc` and `.rhosts` do not exist, and `.forward` is not used.\n",
    "rationale": "A world-readable home exposes documents, history and keys. A shell startup file writable by\nsomeone else lets that person run commands as the user at their next login. `.rhosts` allows\npassword-less login with legacy tools, and `.netrc` stores plain-text passwords.\n",
    "impact": "Other users can no longer browse home directories. Shared files belong in a group directory.\n",
    "notes": "Ubuntu creates new homes with mode `750` since 21.04 (`HOME_MODE` in `/etc/login.defs` for\n`useradd`, `DIR_MODE` in `/etc/adduser.conf` for `adduser`). Ubuntu 20.04 creates them with\n`755`, so the default user of a 20.04 system fails until the fix runs; set `DIR_MODE=0750` in\n`/etc/adduser.conf` there for the next accounts.\n",
    "audit": {
      "manual": "For each interactive account, check `stat -c '%U %a' ~user` (owner is the user, mode 750 or\nstricter), `ls -la ~user/.??*` (no group or world write, owned by the user) and that\n`.netrc`, `.rhosts` and `.forward` are absent.\n",
      "checks": [
        {
          "id": "homes",
          "engine": "shell",
          "description": "Ownership and mode of interactive homes and their dot files.",
          "spec": {
            "script": "rc=0\nawk -F: '$3 >= 1000 && $3 < 65534 && $7 !~ /nologin$|false$/ {print $1 \":\" $6}' /etc/passwd > /tmp/.cb_users.$$\nwhile IFS=: read -r u h; do\n  [ -d \"$h\" ] || { echo \"$u: home $h missing\"; rc=1; continue; }\n  [ \"$(stat -c %U \"$h\")\" = \"$u\" ] || { echo \"$u: home not owned by user\"; rc=1; }\n  m=$(stat -c %a \"$h\"); [ $(( 0$m & 027 )) -eq 0 ] || { echo \"$u: home mode $m\"; rc=1; }\n  for f in \"$h\"/.[!.]* \"$h\"/..?*; do\n    [ -e \"$f\" ] || continue\n    [ -L \"$f\" ] && continue\n    case ${f##*/} in .netrc | .rhosts | .forward) echo \"$u: ${f##*/} present\"; rc=1 ;; esac\n    [ \"$(stat -c %U \"$f\")\" = \"$u\" ] || { echo \"$u: ${f##*/} not owned by user\"; rc=1; }\n    m=$(stat -c %a \"$f\"); [ $(( 0$m & 022 )) -eq 0 ] || { echo \"$u: ${f##*/} mode $m\"; rc=1; }\n  done\ndone < /tmp/.cb_users.$$\nrm -f /tmp/.cb_users.$$\n[ \"$rc\" -eq 0 ] && echo \"all interactive homes are private\"\nexit $rc\n"
          }
        }
      ]
    },
    "remediation": {
      "manual": "For each reported account:\n1. `chown <user> ~user` and `chmod 750 ~user`.\n2. `chown <user> ~user/.<file>` and `chmod go-w ~user/.<file>`.\n3. Remove `.rhosts` and `.netrc` after checking with the user; review and remove `.forward`.\n",
      "effects": {
        "restart": "none",
        "disruption": "low",
        "lockout_risk": false
      },
      "rollback": "Permissions are not backed up: note the previous modes from the audit output before applying.\n",
      "scripts": [
        {
          "id": "permissions",
          "engine": "shell",
          "content": "awk -F: '$3 >= 1000 && $3 < 65534 && $7 !~ /nologin$|false$/ {print $1 \":\" $6}' /etc/passwd |\n  while IFS=: read -r u h; do\n    [ -d \"$h\" ] || continue\n    chown \"$u\" \"$h\"\n    chmod g-w,o-rwx \"$h\"\n    for f in \"$h\"/.[!.]* \"$h\"/..?*; do\n      [ -e \"$f\" ] && [ ! -L \"$f\" ] || continue\n      chown \"$u\" \"$f\"\n      chmod go-w \"$f\"\n    done\n  done\n"
        }
      ]
    },
    "references": [
      {
        "title": "login.defs(5), Ubuntu manual pages (HOME_MODE)",
        "url": "https://manpages.ubuntu.com/manpages/noble/man5/login.defs.5.html",
        "publisher": "Canonical",
        "kind": "vendor-doc",
        "accessed": "2026-10-19"
      },
      {
        "title": "ANSSI-BP-028 v2.0 - Recommandations de configuration d'un système GNU/Linux (R50)",
        "url": "https://messervices.cyber.gouv.fr/documents-guides/fr_np_linux_configuration-v2.0.pdf",
        "publisher": "ANSSI",
        "kind": "guide",
        "accessed": "2026-10-19"
      }
    ],
    "mappings": [
      {
        "framework": "anssi-linux",
        "framework_version": "2.0",
        "id": "R50",
        "relation": "partial"
      },
      {
        "framework": "nist-800-53r5",
        "framework_version": "5.1.1",
        "id": "AC-3",
        "relation": "related"
      }
    ],
    "threats": [
      {
        "framework": "mitre-attack",
        "id": "T1546.004"
      },
      {
        "framework": "cwe",
        "id": "CWE-732"
      }
    ],
    "authors": [
      {
        "name": "Alice",
        "github": "Sn0wAlice"
      }
    ],
    "verified": [
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "20.04"
        ],
        "environment": "Proxmox VM, Ubuntu 20.04 cloud image, kernel 5.4.0-216-generic",
        "notes": "Fails on a fresh install (homes created 755); fix sets 750; kept after reboot; profiles core and server-hardened."
      },
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "22.04"
        ],
        "environment": "Proxmox VM, Ubuntu 22.04 cloud image, kernel 5.15.0-198-generic",
        "notes": "Passes on a fresh install (HOME_MODE 0750); profiles core and server-hardened."
      },
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "24.04"
        ],
        "environment": "Proxmox VM, Ubuntu 24.04 cloud image, kernel 6.8.0-147-generic",
        "notes": "Passes on a fresh install (HOME_MODE 0750); profiles core and server-hardened."
      },
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "26.04"
        ],
        "environment": "Proxmox VM, Ubuntu 26.04 cloud image, kernel 7.0.0-38-generic",
        "notes": "Passes on a fresh install (HOME_MODE 0750); profiles core and server-hardened."
      }
    ],
    "introduced_in": "0.1.0",
    "created": "2026-10-19",
    "updated": "2026-10-19"
  }
}