Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have some rules for example:

KERNEL=="sdb[1-9]", RUN+="some_script.sh"

In some_script.sh how can I determine which user is plug in device.

share|improve this question
    
Just how would you imagine the computer knowing which user did anything on the hardware side? "Hey, I won't let you log in, because you hurt my touchpad yesterday!"? –  rozcietrzewiacz Nov 16 '11 at 14:18
    
OK, you can: get a bunch of cameras monitoring all around the room, analyze all the data via a BioAPI, preferably with some advanced AI algorithms and tell it what person has what account. Easy-peasy ;P –  rozcietrzewiacz Nov 16 '11 at 14:23
    
Funny ... . I was only checking if there is any possibility to determine that. –  PaulP Nov 21 '11 at 10:38
    
Jokes aside, if you are really thinking about detecting any hardware <-> user correlation, the most you can get is a list currently logged-in users (if any). What you'd do with it is a separate aspect for you to decide on. –  rozcietrzewiacz Nov 21 '11 at 10:47

1 Answer 1

Unless the device itself has a means of authentication (a fingerprint reader?), you can't know who plugged it in.

What you can do, and which may or may not suit your purposes, is to determine who is logged in on the console. This requires specific OS support, and there could be no user logged in on the console, or several, or there could be a single user logged in on the console who is nonetheless not the one who plugged the device in.

The best specific support is the pam_console PAM module. You can make it run from udev. It's pioneered by Red Hat and is not available on all distributions.

Another implementation of console users is ConsoleKit. You can invoke it from udev through udev-acl.

share|improve this answer
    
What about situation where are more than one user logged in system, then this solution will not work. Am I right? –  PaulP Oct 25 '11 at 10:34
1  
@PaulP Your question is very vague. What behavior do you want when there are several users logged in? Once you tell us that, we can try to implement your policy. –  Gilles Oct 25 '11 at 10:51
    
Mainly for umount by normal user. When I know which user are plugging in I know for whom use chown. So normal user can umount device which he plugged. –  PaulP Nov 21 '11 at 10:36

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.