Useful User and Group Linux Commands For SysAdmin

Useful User and Group Linux Commands For SysAdmin

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

Below are the commands with detail explanations.

1. id

This command will provide you the no. of active users and their ids. Also, you will get the users login and group information with help of this command.

 

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

2. last

This is a very important command which will give you information about the last login users details on the system.

$ last

prashant pts/10 :0 Wed Nov 2 13:40 still logged in
prashant pts/8 :0 Wed Nov 2 13:13 - 19:23 (06:10)
prashant pts/4 :0 Wed Nov 2 13:04 - 18:32 (05:27)
prashant pts/2 :0 Wed Nov 2 12:54 - 13:40 (00:45)
prashant pts/8 :0 Tue Nov 1 17:14 - 17:17 (00:03)
prashant pts/8 :0 Tue Nov 1 15:57 - 16:04 (00:07)
prashant pts/4 :0 Tue Nov 1 12:36 - 19:35 (06:59)
prashant pts/2 :0 Tue Nov 1 12:08 - 19:35 (07:27)


wtmp begins Tue Nov 1 12:08:05 2016

3. who

Who command will show who is currently logged on the system.

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

4. whoami

This command will provide you the name user by which you are currently logged on the system.

$ whoami
prashant

5. groupadd

Groupadd command allows you to add or create a group on the system. To run this command you must have root access on the system. if you try to run it through normal user it will give you permission denied error.

$ groupadd admin

6. useradd

This command will help you to create a new user on the system. Below command will create the new user and add that user to the admin group.

$ useradd -c "Colin Barschel" -g admin -m colin

You can check a group of "colin" user with id command.

$ id
uid=1005(colin) gid=1006(admin) groups=1006(admin)

7. usermod

usermod command used to modify or change the settings of existing or already created a user account. The only root user is able to execute this command. You can find more options for a usermod command using "usermod --help" on the terminal. Below command helps to add existing user to the group.

$ usermod -a -G Groupname Username

8. groupmod

groupmod command used to modify or change the settings of existing groups. root user only has access to run this command. Here we are using groupmod command to add existing user to the group. This command works similarly to usermod command.

$ groupmod -A Username Groupname

9. userdel

Userdel command used to delete a user from the system.

$ userdel colin

10. adduser

adduser is worked similarly like useradd command but adduser is a more interactive command. adduser is more user-friendly and interactive than its back-end useradd. This command will prompt you to set a password for the user.

$ adduser joe

Adding user `joe' ...
Adding new group `joe' (1007) ...
Adding new user `joe' (1006) with group `joe' ...
Creating home directory `/home/joe' ...
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

11. rmuser

rmuser is used to delete the user. You need to root access to run rmuser command.

$ rmuser joe

I hope you like the article if you find any difficulties using user and group linux commands then please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles.

 

Read : Useful rsync command examples for SysAdmins

Read : Useful MySql Commands Every SysAdmin Should Know

Leave a Reply

Your email address will not be published. Required fields are marked *