Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have userA and userB who start processes:

userA@server:~$ ./some_command.sh &
[1] 30889

I then want userC to be able to manage those processes (suspending, resuming, terminating, and killing):

userC@server:~$ kill 30889
bash: kill: (30889) - Operation not permitted
userC@server:~$ sudo kill 30889
userC@server:~$ 

How can I give permission to userC to do this without relying on sudo access? As a last resort I would grant userC root privilege to do this.

I have complete control over userC. One possibility is changing the user ID to same as userA, but then what about userB?

UPDATE:

The context is for an existing web app.

share|improve this question
add comment

3 Answers

Unless you give userC access to userA and userB's accounts, there's no way to do it without using something like sudo that grants special permission. There's no facility in the Linux kernel to grant access to processes based on groups or access control lists.

But you shouldn't fear using sudo. You can configure it to allow only specific commands and only allow the commands to be run as specific users. I.e. you can allow just userA and userB's process to be killed by userC, but not allow userC to kill other processes.

share|improve this answer
    
For this use case can't use sudo. Worse case is I will run this as root user, but would prefer to avoid that. –  hoju Jan 15 '13 at 4:36
add comment

You could make a second application that can kill processes for example process-proxy, you can run that as root only once (maybe make it start automatically at boot) and leave it listening to for a Dbus message, or some other mean of communication. Finally a client application, for example send-message to send the messages and can be run at will by userC.

userC@server $ ./send-message -kill -pid 30889
userC@server $ ./send-message -nice 2 -pid 30889

In other words make a proxy application. You just need to make sure it only listens for messages from userC, and also may be a good idea to only let it kill specific processes for specific users.

P.D. Dbus may not be the best Idea (I'm not fully familiar with it) but there are plenty of ways to make process-proxy aware of a message. For example, monitor for a file on certain folder (for which only userC and root have access for security) that can contain the pid of the process we need it to kill.

share|improve this answer
    
Then again, given the fact that you prefer not to use sudo, this may be way too gimmicky. –  Martín Canaval Jan 21 '13 at 5:10
    
Not just kill - all types of signals. Was hoping there was a direct way to do this like with file permissions. –  hoju Jan 21 '13 at 8:21
    
The same idea (and drawbacks) still apply. If it helps I'll change some names to make it look more generic. –  Martín Canaval Jan 21 '13 at 8:27
    
Sounds too cumbersome. Additionally the web app does not call kill / etc directly. Uses a third party library for process management. –  hoju Jan 21 '13 at 23:37
add comment

This is similar to Martin’s answer, but (arguably) a bit simpler.  Write a new version of the kill command that looks something like this:

If (current UID (i.e., invoker’s UID) != userC)
        exit (with an appropriate error message)
parse args
call kill() system function

If you’d rather not rewrite the kill command, write your program to exec /bin/kill with whatever arguments were passed to it.  Compile, test, and then make two copies: one that’s setUID to userA and one that’s setUID to userB.  For extra safety, put them in a directory that only userC has access to.

If making life easy for userC is a paramount concern, write a front-end program that determines whose process(es) userC is trying to ‘kill’ and invokes the appropriate copy of the first program.  Or it could run both copies.


This is, essentially, writing your own stripped-down version of sudo, so I don’t know whether it will be acceptable to you.  You said that you want to “do this without relying on sudo access”, and, strictly speaking, with this answer, you wouldn’t be relying on anything –– you would have complete control over the configuration of the solution.

share|improve this answer
    
thing is the web app does not call the kill or similar commands directly. Processes are managed by a third party library. So I was after a permission approach, if possible. –  hoju Jan 21 '13 at 23:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.