Допустим вам нужно предоставить доступ себе к какому-нибудь файлу/папке как члену группы владельца файла, так как самого владельца, в данном случае, изменить нет возможности. Например разрешить просмотр общих папок в VirtualBox в гостевой ОС на базе линукс. Казалось бы, что может быть проще?
1 |
usermod -a -G vboxsf <username> |
Но это изменение не повлияет на уже открытые сессии(если честно, я не понимаю что именно понимать под сессией). Хотя для обхода этого есть хак.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# How to add user into group, and make changes take effect *without logout/login*: the *newgrp* command # # Do note that this method will only update the groups, in the current shell session (and its child-processes). # New shell sessions will not have the groups updated - either use this method to update the groups in each shell # session, or logout/login to make the group update permanent by default # # In short: # $ sudo adduser user_x my_grp # $ newgrp my_grp && newgrp # # Here is the rundown annotated: #Add user_x into group sambashare user_x@stest:~$ sudo adduser user_x sambashare user_x@stest:~$ id uid=1001(user_x) gid=1002(user_x) groups=1002(user_x),20(dialout) #changes did not take effect user_x@stest:~$ newgrp user_x@stest:~$ id uid=1001(user_x) gid=1002(user_x) groups=1002(user_x),20(dialout) #changes still did not take effect user_x@stest:~$ newgrp sambashare user_x@stest:~$ id uid=1001(user_x) gid=115(sambashare) groups=1002(user_x),20(dialout),115(sambashare) #changes *did* take effect now: # - changed 'gid=115(sambashare)' # - appended '115(sambashare)' user_x@stest:~$ newgrp user_x@stest:~$ id uid=1001(user_x) gid=1002(user_x) groups=1002(user_x),20(dialout),115(sambashare) #reestablished 'gid=1002(user_x)' # all done now |
P.S. и да, я не понимаю, из-за чего (софт/ядро/принципы *nix) так, но по крайней мере в Ubuntu 10.04/12.04 поведение такое.