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.