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.

  • 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

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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