Skip to content

Instantly share code, notes, and snippets.

@kofemann
Created August 16, 2012 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kofemann/3368116 to your computer and use it in GitHub Desktop.
Save kofemann/3368116 to your computer and use it in GitHub Desktop.
execute command as a defiend user with X forwarding
#!/bin/sh
#
# execute command as a defiend user with X forwarding
# Example:
# xsu auser gedit /some/text/file
#
if [ $# -lt 2 ]
then
echo "Usage: xsu <user> <command> [args....]"
exit 1
fi
NEW_USER=$1
# drop firs argument
shift
AUTH_FILE=/tmp/xauthexport.$$
xauth list | cut -d ' ' -f1 | xargs -r xauth extract ${AUTH_FILE}
chown ${NEW_USER} ${AUTH_FILE}
su ${NEW_USER} -c "xauth -i merge ${AUTH_FILE}; $*"
rm ${AUTH_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment