Guest User

Untitled

a guest
Oct 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. echo "Current user in script1:" $USER
  4.  
  5. # Call script2
  6. sudo -u user2 /full/path/to/script2
  7.  
  8. #! /bin/bash
  9.  
  10. echo "Current user in script2:" $USER
  11.  
  12. # Execute command as user2
  13. some-command-that-works
  14.  
  15. # /etc/sudoers
  16. #
  17. # This file MUST be edited with the 'visudo' command as root.
  18. #
  19. # See the man page for details on how to write a sudoers file.
  20. #
  21.  
  22. Defaults env_reset
  23.  
  24. # Host alias specification
  25.  
  26. # User alias specification
  27.  
  28. # Cmnd alias specification
  29.  
  30. # User privilege specification
  31. user1 ALL=(ALL:ALL) ALL
  32.  
  33.  
  34. # Allow members of group sudo to execute any command
  35. # (Note that later entries override this, so you might need to move
  36. # it further down)
  37. %sudo ALL=(ALL) ALL
  38. #
  39. #includedir /etc/sudoers.d
  40.  
  41. # Don't ask for user2 password for script2
  42. user2 ALL= NOPASSWD: /full/path/to/script2
  43.  
  44. # FYI: I experimented with the line below for group1 that user1 is a member of
  45. %group1 ALL= NOPASSWD: /full/path/to/script2
  46.  
  47. drwxrwsr-x 2 user1 group1 4.0K Oct 19 15:22 .
  48. drwxrwsr-x 7 user1 group1 4.0K Oct 18 18:48 ..
  49. -rwxrwxr-x 1 user1 group1 180 Oct 20 17:37 script1
  50. -rwx------ 1 user2 group1 166 Oct 20 16:29 script2
  51.  
  52. user1@host1 /full/path/to/script1 $ script1
  53. Current user in script1: user1
  54. [sudo] password for user1:
Add Comment
Please, Sign In to add comment