Set user

2 snippets across 2 stacks - Bash & Linux, Docker

SHBash & Linux

Change File Owner

SH · Permissions & Ownership
Syntax
chown [options] user[:group] file...
Example
sudo chown www-data:www-data /var/www/html -R
sudo chown deploy app/
sudo chown :staff shared/

Note Requires root/sudo for files you do not own. user:group changes both at once. :group (with colon, no user) changes only the group. -R applies recursively. Be careful with -R on directories containing symlinks; use --no-dereference to avoid following them.

DKDocker

USER - Set Runtime User

DK · Dockerfile
Syntax
USER <username>[:<group>]
Example
RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
USER appuser

Note All subsequent RUN, CMD, and ENTRYPOINT instructions run as this user. Running as root in production is a security risk - always create and switch to a non-root user for the final stage.

Frequently asked questions

How does Bash & Linux handle set user?
This task is covered in 2 stacks on this page: Bash & Linux, Docker. The "Change File Owner" snippet in Bash & Linux uses `chown [options] user[:group] file...`.
Which command does the Bash & Linux example use?
The "Change File Owner" snippet uses `chown [options] user[:group] file...`, from the Permissions & Ownership section of the Bash & Linux cheat sheet.
Which stacks cover "set user" on this page?
Bash & Linux, Docker. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Change File Owner": Requires root/sudo for files you do not own. user:group changes both at once. :group (with colon, no user) changes only the group. -R applies recursively. Be careful with -R on directories containing symlinks; use --no-dereference to avoid following them.