Linux Administrator

Linux Commands : Useful User And Group Commands For Linux Users

mm
Written by Santosh Prasad

This post provides some Linux commands that can be utilized for user and group related assignments. with this commands, you can add,remove,delete users and groups. To run certain commands you should have root or sudo level rights on Linux machine.

Following are the commands in depth:

Id

Id commands provides the number of active users and their IDs. Using this command can get the users login and group information.

# id
uid=0(root) gid=0(root) groups=0(root)

Last

last command is used to get the last login user detail on the system.

# last
reboot   system boot  2.6.32-042stab08 Sun Jul  5 13:54 - 12:54 (801+23:00)
reboot   system boot  2.6.32-042stab08 Fri Mar  7 03:21 - 13:53 (485+09:31)
reboot   system boot  2.6.32-042stab05 Mon Sep 17 22:37 - 13:53 (1020+15:15)
reboot   system boot  2.6.32-042stab05 Mon Sep 17 20:07 - 22:36  (02:28)
reboot   system boot  2.6.32-042stab05 Tue Apr 24 20:06 - 20:07 (146+00:00)
reboot   system boot  2.6.32-042stab05 Thu Apr 12 22:14 - 20:07 (157+21:52)
reboot   system boot  2.6.18-194.8.1.e Mon Apr  2 10:06 - 22:13 (10+12:06)
reboot   system boot  2.6.32-042stab03 Tue Feb 21 10:41 - 03:30 (40+15:49)
wizap    pts/1        c-68-51-136-80.h Sun Nov 20 11:16 - 12:00  (00:43)
reboot   system boot  2.6.32-042stab03 Mon Nov  7 06:52 - 03:30 (146+19:38)

Who

Who command display the current logged in user on the system.

# who
prashant tty8 2017-10-03 12:20 (:0)
prashant pts/10 2017-11-02 13:40 (:0)

Whoami

Whois command provides the name of the user by which you are currently logged on the system.

# whoami
root

Groupadd

This command used to create a group on the system. Before running this command make sure a are logged in as a root otherwise you get “permission denied” error.

# groupadd dba

Useradd

Useradd command used to create a user on the system. Type the below command create a new user and add that user to the dba group.

# useradd -c "Rahul Sharma " -g admin -m rahul

You can check a group of “rahul” user with id command like below:

# id rahul
uid=81(rahul) gid=81(dba) groups=81(dba)

Usermod

This command used modify or change the setting of existing user account. Only root user can modify the existing user account. Using usermod –help you can get more options.

 # usermod -a -G Groupname Username

Groupmod

This command used to modify or change the setting of existing group. Only root user can modify the existing group. This command works similarly to usremoad command.

 # groupmod -A Username Groupname

Userdel

This command is used to delete the user from the system.

# userdel rahul

Adduser

This command works same as useradd command but it is more interactive command. It is also user friendly and interactive. This command is also prompt to set a password for the user.

# adduser neo

Adding user `neo' ...
Adding new group `neo' (1007) ...
Adding new user `neo' (1006) with group `neo' ...
Creating home directory `/home/neo' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for joe
Enter the new value, or press ENTER for the default
Full Name []: 
Room Number []: 
Work Phone []: 
Home Phone []: 
Other []: 
Is the information correct? [Y/n] y

Rmuser

This command used to delete the user from the system.

# rmuser neo

Suggested Read:

Thanks:)

Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment