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, orapache) 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 filenameinstead of the correctchown user:group filenamestructure. - Active Directory / LDAP Authentication Desynchronisation: Domain users not resolving because the
sssdorwinbinddaemon 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.
- Open your Terminal shell.
- Query the system password database using
getentorgrep:getent passwd username - Replace
usernamewith the account name you are trying to assign (e.g.www-dataordeploy). - 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.
- 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 - To create a regular user account with a home directory:
sudo adduser newusername - Verify the account is registered by running:
id newusername - Re-run your
chowncommand 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.
- If your command uses a dot separator:
# Deprecated syntax: sudo chown user.group /var/www/html - Update the command to use a colon:
# Standard modern syntax: sudo chown user:group /var/www/html - 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.
- Check group registration using:
getent group groupname - If the group is missing, create it using:
sudo groupadd groupname - 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:
- Check if the domain user is visible to the Name Service Switch:
id "domain\username" # or id [email protected] - If domain users fail resolution, clear the SSSD credential cache:
sudo sss_cache -E sudo systemctl restart sssd - When referencing domain accounts in chown, always wrap domain names containing backslashes in quotes:
sudo chown "DOMAIN\user":"DOMAIN\group" /path/to/folder