📜  添加组而不注销 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:50:53.857000             🧑  作者: Mango

代码示例1
# Horribly hacky, but you could use two layers of newgrp to achieve this for a particular group:

id -g

# ...will give you the current primary group ID. We'll call this orig_group for the purposes of this example. Then:

newgrp 

# ...will switch you to that group as the primary and add it to the list of groups returned by groups or id -G. Now, a further:

newgrp 

# ...will get you a shell in which you can see the new group and the primary is the original one.
# This is horrible and will only get you one group added at a time, but it has helped me out a couple of times to get groups added without logging out/in my whole X session (e.g. to get fuse added as a group to a user so that sshfs will work).
# Edit : This doesn't require you to type your password either, which su will.