A little known tool: newgrp
by pstradomski at 2009-04-02 14:43
Documentation of various linux programs often states that after adding user to some unix group you need to re-login in order to use new privileges. Although this is definitely the easiest option, it is still possible to enhance user's groupset without re-logging.
After adding user to the group you can use newgrp group_name. This is an old tool (from the time when unix users could use privileges of only one group at a time) that changes the current group for user. Additionally, it tries to add the group to the current groupset for the user.
For example:
$ id uid=1000(pawel) gid=1000(pawel) grupy=6(disk),10(wheel),11(floppy),18(audio), 19(cdrom),27(video),80(cdrw),85(usb),100(users), 443(plugdev),1000(pawel),1004(www),1005(ssmtp), 1006(vboxusers),1007(kvm) $ newgrp wireshark $ id uid=1000(pawel) gid=1008(wireshark) grupy=6(disk),10(wheel),11(floppy),18(audio), 19(cdrom),27(video),80(cdrw),85(usb),100(users), 443(plugdev),1000(pawel),1004(www),1005(ssmtp), 1006(vboxusers),1007(kvm),1008(wireshark)
Unfortunately, the current group changed. To have it back to user's default group just run newgrp again:
$ newgrp $ id uid=1000(pawel) gid=1000(pawel) grupy=6(disk),10(wheel),11(floppy),18(audio), 19(cdrom),27(video),80(cdrw),85(usb),100(users), 443(plugdev),1000(pawel),1004(www),1005(ssmtp), 1006(vboxusers),1007(kvm),1008(wireshark)
This only affects the current shell, but should be enough to just run a single program (like wireshark or some cd burninig software like k3b).
Oh, and just plain su - mylogin would also work - but it asks for a password :)
Comments