Saturday 19 September 2015

How to Manage Users and Groups in Linux via Terminal



      How to Manage Users and Groups in Linux via Terminal

 
1)
Add new group named "school"

            anusree@anusree-VirtualBox:~$ sudo groupadd school


2)
List the group that created in above step.

           anusree@anusree-VirtualBox:~$ cat /etc/group


3)
Add two users named "students" and "staffs"

             anusree@anusree-VirtualBox:~$ sudo useradd -m students
             anusree@anusree-VirtualBox:~$ sudo useradd -m staffs
  

-m option is used for crate the home directory at the time of user is created.

4)
List the users that created in the above step.

             anusree@anusree-VirtualBox:~$ cat /etc/passwd


5)
Then, add the existing users "students" and "staffs" to the group "school".

               anusree@anusree-VirtualBox:~$ sudo adduser students school
               Adding user `students' to group `school' ...
               Adding user students to group school
               Done.
               anusree@anusree-VirtualBox:~$ sudo adduser staffs school
               Adding user `staffs' to group `school' ...
               Adding user staffs to group school
               Done.
                anusree@anusree-VirtualBox:~$


After adding users to the group then list the name of groups then we can see the changes..


6)
Delete the user.

              anusree@anusree-VirtualBox:~$ sudo userdel -r students         
              anusree@anusree-VirtualBox:~$ sudo userdel -r staffs

 -r option is used for delete the user with its home directory 

7)
Delete the group.

             anusree@anusree-VirtualBox:~$ sudo groupdel school