Skip to content

Instantly share code, notes, and snippets.

@azazar
Last active January 20, 2024 07:57
Show Gist options
  • Save azazar/41d170f38e6762fb6912aa15c58304f0 to your computer and use it in GitHub Desktop.
Save azazar/41d170f38e6762fb6912aa15c58304f0 to your computer and use it in GitHub Desktop.
Aliases that changes the current directory to the home directory of a specified user and then starts a new shell session as that user.
# For users with read-only or otherwise unusable HOME directory
alias www='sudo -u www-data /bin/bash -c "mkdir -p /tmp/$(id -n -u)-home && cd /tmp/$(id -n -u)-home && (test -e realhome || ln -s $(getent passwd www-data|cut -d':' -f6) realhome) && HOME=/tmp/$(id -n -u)-home exec /bin/bash -l"'
# For users with writable HOME
alias uuu='cd $(getent passwd www-data|cut -d':' -f6) && sudo -u www-data -s /bin/bash'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment