How to Fix ‘chown: invalid user’ Error in Linux

Managing file permissions or web directory ownership in Linux using the change owner command only to be halted by: chown: invalid user: 'username:group' or chown: invalid user: 'www-data' prevents permission reassignment. The chown utility modifies file system user and group ownership metadata on Unix/Linux inodes. When the command parser cannot locate the specified username in the system’s local user database (/etc/passwd) or NSS directory service (LDAP/Active Directory), or when a syntax error confuses the user and group separator, Linux rejects the command immediately.

Why Does Linux Return chown: invalid user?

The operating system verifies user existence before updating filesystem ownership flags. The error arises from:

  • Non-Existent User Account: The target user (such as www-data, nginx, or apache) not being created on the operating system because the corresponding service package is not installed.
  • Syntax Delimiter Incompatibilities: Using an outdated dot separator (user.group) instead of the standard colon separator (user:group), confusing usernames containing periods.
  • Accidental Inversion of User and Group: Writing chown group:user filename instead of the correct chown user:group filename structure.
  • Active Directory / LDAP Authentication Desynchronisation: Domain users not resolving because the sssd or winbind daemon has lost its domain controller connection.

Step 1: Verify the Target User Exists in /etc/passwd

Confirm whether the account you are attempting to assign exists in the local system database.

  1. Open your Terminal shell.
  2. Query the system password database using getent or grep:
    getent passwd username
  3. Replace username with the account name you are trying to assign (e.g. www-data or deploy).
  4. If the command returns no output, the user account does not exist on your machine and must be created first.

Step 2: Create the Missing User Account

If the user account is absent, create a dedicated system account or standard user account.

  1. To create a service/system user with no login shell (common for web servers like NGINX or Apache):
    sudo useradd -r -s /usr/sbin/nologin www-data
  2. To create a regular user account with a home directory:
    sudo adduser newusername
  3. Verify the account is registered by running:
    id newusername
  4. Re-run your chown command to verify ownership assignment succeeds.

Step 3: Use the Standard Colon Delimiter for User and Group

Historical versions of Unix supported a dot (user.group), but modern Linux distributions require a colon (user:group) to prevent collisions with usernames containing dots.

  1. If your command uses a dot separator:
    # Deprecated syntax:
    sudo chown user.group /var/www/html
  2. Update the command to use a colon:
    # Standard modern syntax:
    sudo chown user:group /var/www/html
  3. If you only wish to change the group ownership without altering the user, prefix the group name with a colon:
    sudo chown :groupname /var/www/html

Step 4: Check Group Existence in /etc/group

If specifying both user and group, verify that the group exists to isolate whether the user or group name triggered the failure.

  1. Check group registration using:
    getent group groupname
  2. If the group is missing, create it using:
    sudo groupadd groupname
  3. Add your user to the newly created group:
    sudo usermod -aG groupname username

Step 5: Refresh Domain Controller SSSD Cache for LDAP Users

If working in an enterprise environment where user accounts reside on Active Directory or LDAP:

  1. Check if the domain user is visible to the Name Service Switch:
    id "domain\username"
    # or
    id [email protected]
  2. If domain users fail resolution, clear the SSSD credential cache:
    sudo sss_cache -E
    sudo systemctl restart sssd
  3. When referencing domain accounts in chown, always wrap domain names containing backslashes in quotes:
    sudo chown "DOMAIN\user":"DOMAIN\group" /path/to/folder

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.