# Ensure no duplicate UIDs exist

Necessity: The User ID (UID) is the primary identifier the kernel uses to determine resource access and ownership. If multiple user accounts share the same UID, the system treats them as the same user from a permissions standpoint. This fundamentally breaks the principle of least privilege and accountability. It can lead to unauthorized access to files and processes, and makes auditing impossible as actions performed by one user are indistinguishable from the other. This misconfiguration could allow a non-privileged user to inherit the permissions of a privileged system or user account, leading to privilege escalation.

Auditing and Remediation: The audit script checks the system's user database (`/etc/passwd`) by extracting the UID field for each user and identifying any UIDs that are assigned to more than one account. It reports the total count of such duplicates. Remediation is a complex manual process. An administrator must use commands like `usermod` to assign a new, unique UID to one of the conflicting accounts and then use `find` and `chown` to recursively update the ownership of all files and directories previously owned by the old UID. Due to the high risk of data inaccessibility or system instability, automated remediation is not recommended.

Recommended State Rationale: The recommended state for all security levels (Basic, Moderate, and Strict) is an absolute value of 0. There is no acceptable scenario for duplicate UIDs on a system. The presence of even a single duplicate UID is a critical security vulnerability that undermines the entire user-based access control model. Therefore, the only secure configuration is to ensure that every user account has a unique UID.

## Recommended State Configuration

| Security Level | Value |
|----------------|-------|
| **Basic** | `[0, 0]` |
| **Moderate** | `[0, 0]` |
| **Strict** | `[0, 0]` |
| **Type** | `RANGE` |

## Audit Script Working

Bash script that counts the number of user IDs (UIDs) that are assigned to more than one user account. The script must parse the '/etc/passwd' file, identify any UIDs that appear more than once, and return a single integer representing the total count of such duplicate UIDs. The output must be only the number, with no additional text or formatting.

## Remediation Script Working

Bash script for a post-remediation check. Since automatically changing a User ID (UID) is a high-risk operation requiring manual intervention to re-associate file ownership, this script will not perform any changes. Instead, it will re-audit the system for duplicate UIDs. If the number of duplicate UIDs is zero, it must return 'true'. If any duplicate UIDs are found, it must return 'false'. The script should be designed to ignore any command-line arguments as no direct setting can be applied.

