Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- echo "Current user in script1:" $USER
- # Call script2
- sudo -u user2 /full/path/to/script2
- #! /bin/bash
- echo "Current user in script2:" $USER
- # Execute command as user2
- some-command-that-works
- # /etc/sudoers
- #
- # This file MUST be edited with the 'visudo' command as root.
- #
- # See the man page for details on how to write a sudoers file.
- #
- Defaults env_reset
- # Host alias specification
- # User alias specification
- # Cmnd alias specification
- # User privilege specification
- user1 ALL=(ALL:ALL) ALL
- # Allow members of group sudo to execute any command
- # (Note that later entries override this, so you might need to move
- # it further down)
- %sudo ALL=(ALL) ALL
- #
- #includedir /etc/sudoers.d
- # Don't ask for user2 password for script2
- user2 ALL= NOPASSWD: /full/path/to/script2
- # FYI: I experimented with the line below for group1 that user1 is a member of
- %group1 ALL= NOPASSWD: /full/path/to/script2
- drwxrwsr-x 2 user1 group1 4.0K Oct 19 15:22 .
- drwxrwsr-x 7 user1 group1 4.0K Oct 18 18:48 ..
- -rwxrwxr-x 1 user1 group1 180 Oct 20 17:37 script1
- -rwx------ 1 user2 group1 166 Oct 20 16:29 script2
- user1@host1 /full/path/to/script1 $ script1
- Current user in script1: user1
- [sudo] password for user1:
Add Comment
Please, Sign In to add comment