Skip to content

Instantly share code, notes, and snippets.

@kawanet
Created May 27, 2015 16:53
Show Gist options
  • Select an option

  • Save kawanet/cf7bb8363733007c4d9c to your computer and use it in GitHub Desktop.

Select an option

Save kawanet/cf7bb8363733007c4d9c to your computer and use it in GitHub Desktop.
root 権限で実行されていたら特定ユーザに su してシェルスクリプトを起動し直す
#!/bin/sh
# re-launch itself with a specified user when launched with root user
[ "$(id -u)" -eq 0 ] && exec su - "someuser" -c "$0 $*"
# do something
whoami
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment