Controlling USB device access per user on a Linux box

1

I want to write a udev rule that blocks access to USB storage. I want to add match options that can recognise the username and permit only some users to use USB storage.

How can I find out which user(s) a currently logged in?

Behrad Irani

Posted 2015-10-07T10:59:24.630

Reputation: 11

Answers

1

Why do you think you need such a complicated approach which also will cause trouble in any multi-user scenario? Why detect user logons?

I think you should simply write a udev rule which changes device access rights (group and its permissions) for the USB subsystem, and maintain access via the group memebrship of users. This is a standard case for udev rules.

Run CMD

Posted 2015-10-07T10:59:24.630

Reputation: 508

This is a much better aproach and much less work that trying to get udev to do this. – Mogget – 2015-10-07T17:10:51.880

I dont want user need logout and login again after i add permisstion for him. – Behrad Irani – 2015-10-13T09:43:38.907

@BehradIrani You're welcome. It was a pleasure answering your question. It's interesting to learn that you have requirements which you did not mention at first. But it's very hard to tell from your comment whether you did any unsuccessful research already, because there are solutions to your, erm, complaint. See e.g. man newgrp. But somebody with your knowledge may be better off with solutions he can understand, even if they cause other problems which he isn't aware of. – Run CMD – 2015-10-13T11:27:03.217

I know about newgrp. but not for my enviroment.(users dont know about command line). I only need some way to find which user logged in on console. – Behrad Irani – 2015-10-19T17:56:51.270

I think i found my answer. i find active login in /sys/class/tty/tty0/active. combination of content of this file and output of "w" i can find user. – Behrad Irani – 2015-10-19T18:24:51.160