Wednesday 15 July 2015

linux - Switch between users with sudo while running shell script -


I have access to group machines (Linux-boxes) and I have created users on them.

I need to run some commands which require sudo

but the rest of the command should be run with the user who can not do sudo.

UPDATE : The expected script shows a good example.

If you type sudo (usually a sudo group member on Debian system), you can run a command as any other user:

  sudo -u no ls   

From the manpage of sudo:

  -u User causes the sudo to run a specified command in the form of a user other than the -u (user) option root, instead of the UID specified UI name To do this, use #UID when UID If the commands are running as a person, then many shells require that '#' escape from a backslash ('\'). Security policies can restrict the UD for those listed in the password database. The Sudoers policy allows the UID that the password is not in the database, unless the targetpw option is set. Other security policies do not support this. Usually, you can create a script that adds to your favorite sudoer, runs some  sudo  as root, and the other All others run as users.   

No comments:

Post a Comment