Skip to content

Instantly share code, notes, and snippets.

@dimti
Last active October 23, 2024 14:03
Show Gist options
  • Save dimti/31ba1974f97911b40b7c25482b282a1b to your computer and use it in GitHub Desktop.
Save dimti/31ba1974f97911b40b7c25482b282a1b to your computer and use it in GitHub Desktop.
Swap users uids
SITE_USER=mysiteuser
SITE_GROUP=$(id $SITE_USER | sed -E 's/.+gid=[[:digit:]]+\(([^)]+)\).+/\1/g')
PROJECT_DIR=/var/www/mysiteproject
BUTHEAD_USER=dimti
FROM_UID=1001
TO_UID=1000
INTERMEDIATE_UID=1002
usermod -u $INTERMEDIATE_UID $BUTHEAD_USER && \
groupmod -g $INTERMEDIATE_UID $BUTHEAD_USER && \
usermod -u $TO_UID $SITE_USER && \
groupmod -g $TO_UID $SITE_GROUP && \
chown -Rh --from=$FROM_UID $TO_UID $PROJECT_DIR && \
chown -Rh --from=:$FROM_UID :$TO_UID $PROJECT_DIR && \
usermod -u $FROM_UID $BUTHEAD_USER && \
groupmod -g $FROM_UID $BUTHEAD_USER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment