Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 668  / 2 Years ago, sat, march 12, 2022, 12:09:04

When a user logs in I need to execute a command that needs escalated privileges. I don't want to give the user sudo access for that command. I just want to run this script for that user, not for all users.


More From » login

 Answers
7

Based on your comment, it sounds like you want user 'fred' to not have a regular shell but run the script 'foo' upon login. This can be done easily if you don't expect Fred to try very hard to escape his "sandbox".



$ cat ~fred/.bash_login
#!/bin/bash
exec /usr/local/bin/foo

## in ubuntu each user has a group of his "own"
$ sudo chown foo:fred ~fred ~fred/.bash_login /usr/local/bin/foo
## prevent fred from altering the files and directories we care about
$ sudo chmod g-w ~fred ~fred/.bash_login /usr/local/bin/foo
## make script foo run with user foo's privileges
$ sudo chmod u+s /usr/local/bin/foo


So fred will now not even get a shell prompt because the first thing his login shell does is replace itself with foo; when script foo exits, fred will be logged out. The reason Fred should lack motivation to climb out of this sandbox is that many programs allow subordinate shells to be opened which would allow fred to undo the poor-man's lockout shown here.



Using this method with "root" instead of some non-superuser foo can be used to hijack root, so don't do that.


[#32013] Sunday, March 13, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bewre

Total Points: 164
Total Questions: 108
Total Answers: 106

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
bewre questions
Sun, May 14, 23, 13:27, 1 Year ago
Mon, Aug 2, 21, 03:57, 3 Years ago
Thu, Aug 26, 21, 18:05, 3 Years ago
Sat, Aug 6, 22, 21:41, 2 Years ago
Sat, Jul 24, 21, 22:52, 3 Years ago
;