--- title: chown โ€” change owner and group date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Command that changes the owner and group of files and directories. Half the solution to permission issues. tags: program, File and disk management, chown --- **๐Ÿ’ฌ "chown command"** Even if permissions are correct, **if the owner is wrong**, access is denied. chown changes the owner/group. The format is `chown user:group path`. - **Concept**: Changes the owner and group of a file. - **Left argument**: User or user:group format. - **Right argument**: Target file/directory. - **Check**: Verify the change with stat or ls -l. ## Commonly used options | Option | Description | | --- | --- | | -R | Recursively changes subitems | | --reference=f | Matches the owner/group of another file | | -h | Changes the owner of the symbolic link itself | | -c | Outputs only changed items | ## 3 essential command combinations - `chown -R www-data:www-data /var/www/html` โ€” changes the entire web root to be owned by the web server account - `chown deploy:deploy /opt/app/current/public/index.php` โ€” specifies the owner of a deployment file - `chown --reference=/etc/nginx/nginx.conf /etc/nginx/conf.d/site.conf` โ€” unifies the ownership of config files **๐Ÿ’ฌ "Show me an example of viewing time-based trends with this command"** Situations commonly encountered on production servers are organized in order. ### Step 1 ยท Check current owner See who owns it and what the web server account is. ``` stat -c '%n %U:%G' /var/www/html ``` ### Step 2 ยท Change owner The web root is usually owned by www-data (or nginx). ``` chown -R www-data:www-data /var/www/html ``` ### Step 3 ยท Verify Check the response and logs. ``` curl -sI https://example.com | head -1 ``` ## How it's used in practice ### 1. Ownership mismatch after deployment **Situation** โ€” A deployment script ran as root, so files became owned by root. ``` chown -R deploy:www-data /opt/app/current ``` **Result** โ€” The app can write files and permission errors disappear. **Point** โ€” Defining the deployment user, service user, and group structure in advance prevents recurring problems. ### 2. Upload write failure **Situation** โ€” Only uploads keep failing. Reading works. ``` chown -R www-data:www-data /var/www/html/uploads && chmod 755 /var/www/html/uploads ``` **Result** โ€” The service account can write to the directory. **Point** โ€” Write failures are often an ownership issue. Don't just fiddle with permissions; check the owner. ## Cautionary notes - Running -R on a system path (/) by mistake can seriously damage the server. Double-check absolute paths. - For symbolic links, the target's owner changes by default. To change the link itself, use -h. - New files created by the app become owned by the running user, so use group inheritance (setgid) if needed. ## Actual execution screen This is the result of changing the web root owner to the web server account and then checking it. ![chown command execution result: checking owner and group](https://games.aidebatehub.com/assets/chown-demo.png) Production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/chown.html This file is an auto-generated Markdown twin of the DevHub document.