OSX su command issue
sudo su will do the trick in Mac Os X terminal 🙂
sudo su will do the trick in Mac Os X terminal 🙂
Try this: su somebody <<‘EOF’ command1 -p ‘parameter with “quotes” inline’ command2 -p ‘parameter with “quotes” inline’ command3 -p ‘parameter with “quotes” inline’ EOF << introduces a here-doc. The next token is the delimiter, and everything up to a line beginning with the delimiter is fed as standard input to the command. Putting the delimiter … Read more
Results: Use who am i | awk ‘{print $1}’ OR logname as no other methods are guaranteed. Logged in as self: evan> echo $USER evan evan> echo $SUDO_USER evan> echo $LOGNAME evan evan> whoami evan evan> who am i | awk ‘{print $1}’ evan evan> logname evan evan> Normal sudo: evan> sudo -s root> echo … Read more
try running: su -c “Your command right here” -s /bin/sh username This will run the command as username given that you have permissions to sudo as that user.
For sudo there is a -S option for accepting the password from standard input. Here is the man entry: -S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. This will allow you to run a command like: echo myPassword | sudo -S ls /tmp … Read more
Much simpler: use sudo to run a shell and use a heredoc to feed it commands. #!/usr/bin/env bash whoami sudo -i -u someuser bash << EOF echo “In” whoami EOF echo “Out” whoami (answer originally on SuperUser)