將一個已有用戶 testuser 增加到一個已有用戶組 root 中,使此用戶組成為該用戶的附加用戶組,可以使用帶 -a 參數的 usermod
指令。-a 代表 append, 也就是將用戶添加到新用戶組中而不必離開原有的其他用戶組。不過需要與 -G 選項配合使用:
usermod -a -G root testuser
如果要同時將 testuser 的主要用戶組改為 root,則直接使用 -g 選項:
usermod -g root testuser
如果要將testuser用戶從root組中刪除,則
gpasswd -d testuser root