In this tutorial I’ll discuss about user and group management on linux. When you using linux operating system you must know to manage user and group on your system. In linux system user and group has unique id. For user it called as UID (User ID) and for group is GID (Group ID).
UID has ranges number :
- UID 0 are used for root user
- UID 1-200 are used for system users that are assign as statically to the system process.
- UID 201-999 are used for system users that are assign as dynamically to the system process that do not own files on the system.
- UID 1000+ are used for regular user.
To create new user you can use useradd or adduser and to create new group you can use groupadd.
If you use linux ubuntu, you can use useradd command for add user, password and home directory as automatically. If you use adduser you have to configure it manually.
root@Taufik:~# adduser user1 Adding user `user1' ... Adding new group `user1' (1003) ... Adding new user `user1' (1003) with group `user1' ... Creating home directory `/home/user1' ... Copying files from `/etc/skel' ... New password: type your password user Retype new password: retype your password user passwd: password updated successfully Changing the user information for user1 Enter the new value, or press ENTER for the default Full Name []: user1 Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] enter root@Taufik:~#
As you shown above, when you add the new user, it will be create new user with UID number is 1003 and it will also create new group with GID number is 1003 and create home directory on /home/user1.
To show user information you can see at /etc/passwd
root@Taufik:~# tail /etc/passwd systemd-resolve:x:103:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin messagebus:x:104:106::/nonexistent:/usr/sbin/nologin pulse:x:105:107:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin xrdp:x:106:109::/run/xrdp:/usr/sbin/nologin admin:x:1000:1000:,,,:/home/admin:/bin/bash usbmux:x:107:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin sshd:x:108:65534::/run/sshd:/usr/sbin/nologin user1:x:1003:1003:user1,,,:/home/user1:/bin/bash
To create new group you can use groupadd command :
root@Taufik:~# groupadd NEWGROUP
Show group information list on /etc/group :
root@Taufik:~# tail /etc/group input:x:110: kvm:x:111: render:x:112: admin:x:1000: ssh:x:113: taufik:x:1001: user12:x:1002: user1:x:1003: NEWGROUP:x:1005:
To create new user with exiting group (NEWGROUP) you can use command : useradd –group GID newuser
root@Taufik:~# useradd --group 1005 user2 root@Taufik:~# tail /etc/group kvm:x:111: render:x:112: admin:x:1000: ssh:x:113: taufik:x:1001: user12:x:1002: user1:x:1003: NEWG:x:1004: NEWGROUP:x:1005:user2 user2:x:1006:
To add supplementary group on the existing user you can use command : usermod -aG GID username
root@Taufik:~# usermod -aG 1005 user1 root@Taufik:~# tail /etc/group kvm:x:111: render:x:112: admin:x:1000: ssh:x:113: taufik:x:1001: user12:x:1002: user1:x:1003: NEWG:x:1004: NEWGROUP:x:1005:user2,user1 user2:x:1006: