There are two types of group. First is primary user group and other is secondary group. Group infomation is stored in /etc/group file contains basic group attributes. This is an ASCII file that contains records for system groups.
useradd command
You need to add new users to existing group. The syntax is as follows:
# useradd -g <groupname> <username>
Example, create a new user called user1 and add it to group called admin. First login as a root user (make sure group admin exists), type the following command
# useradd -g admin user1
Ensure that user added properly to group admin, enter
# id user1
Output
uid=503(user1) gid=502(admin) groups=502(admin)
usermod command
If you need to add a existing user to existing group, type the command with syntax is as follows
# usermod -G <groupname> <username>
To add user to a list of supplementary groups, enter
# usermod -G group1, group2, group3 username
How to remove existing Linux user from existing group? See example bellow
#id test
Output
uid=503(test) gid=501(www) groups=501(www),4(adm),50(ftp)
To remove adm group from user test, type the following command
# usermod -G www,ftp test
Ensure that adm group removed from user test, enter
# id test
Output
uid=503(test) gid=501(www) groups=501(www),50(ftp)
Change existing user test primary group to ftp, enter
usermod -g ftp test
Output
uid=503(test) gid=50(ftp) groups=50(ftp),501(www)
Please note that “-g” option add user to initial login group (primary group). The group name must exist. And “-G” option add user to a list of supplementary groups
Related Posts:
- Setting Up Password Aging In Linux
- How To Install Subversion (SVN) Extension Working With PHP 5.3
- How To Setup Iptables Firewall For A Web Server On CentOS
- How Do I Fix “Host is blocked because of many connection error” In MySQL
- How To Start / Shutdown / Reboot Guest Operating Systems With virsh Command On KVM
- Repel port flood by CSF and IPT_Recent
- What is the role of this variables in php.ini file (expose_php – allow_url_fopen – register_globals) ?
- How Do I Block An IP Address On Linux Server ?
- How To Flush The Entire Contents Of Memcache Server
- How To Setup A LAMP Server On Centos 6.0
{ 1 comment… read it below or add one }
You have mentioned that to remove a group from a user type like below :
# usermod -G www,ftp test
But suppose we have hundreds of groups then this command is very painful to type. We could do this easily by deleting the mentioned group only by this command :
# gpasswd -d username groupname
# gpasswd -d test adm