DEV Community

loading...

User Management in Linux

nadirbasalamah profile image nadirbasalamah ・2 min read

User Management in Linux

User management in linux can be done by using many commands that already provided. User management in linux includes the management of user and group of users.

User management operation is recommended using root user. To login as root user, use sudo -i command then enter the username and password.

Create new user

To create a new user, use adduser command.

adduser fox
Enter fullscreen mode Exit fullscreen mode

Then, insert related data to the new user.

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for fox
Enter the new value, or press ENTER for the default
        Full Name []: fox mccloud
        Room Number []: 64
        Work Phone []: 123123
        Home Phone []: 123123
        Other []:
Is the information correct? [Y/n] Y
Enter fullscreen mode Exit fullscreen mode

The useradd command is also available for creating new user. With this command, the additional information about the new user isn't needed.

useradd nathan
Enter fullscreen mode Exit fullscreen mode

Change an user's password

To change certain user's password, use passwd command.

passwd nathan
Enter fullscreen mode Exit fullscreen mode

To change password for group, use gpasswd command.

gpasswd mygroup
Enter fullscreen mode Exit fullscreen mode

View list of users

All available users can be seen with more /etc/passwd. This is the output example.

fox:x:1001:1001:fox mccloud,64,123123,123123:/home/fox:/bin/bash
Enter fullscreen mode Exit fullscreen mode

This output includes many information such as username for login, password, user ID, group ID, additional informations, home directory and login shell.

Remove an user

To remove an user, use userdel command followed with user's name.

userdel nathan
Enter fullscreen mode Exit fullscreen mode

To remove an user include it's home directory, use userdel -r command.

userdel -r test
Enter fullscreen mode Exit fullscreen mode

Create a group

To create a new group, use groupadd command followed with group name.

groupadd ravenwest
Enter fullscreen mode Exit fullscreen mode

To add a new member into a group, use this command. In this command, the user with username nathan is added into ravenwest group.

usermod -a -G ravenwest nathan
Enter fullscreen mode Exit fullscreen mode

View a list of groups

To view a list of groups, use more /etc/group command. This is the output example from the command.

ravenwest:x:1003:nathan,harrison
Enter fullscreen mode Exit fullscreen mode

This output includes many information such as group's name, encrypted password, GID number, group's members.

Remove a group

To remove a group, use delgroup command followed with group name.

delgroup ravenwest
Enter fullscreen mode Exit fullscreen mode

To remove an user from certain group, use deluser command. In this example, the user with username fox is removed from group called ravenwest.

deluser fox ravenwest
Enter fullscreen mode Exit fullscreen mode

I hope this article is helpful for learning user management in linux, if you have any thoughts or feedbacks. You can write in the discussion section below.

Discussion (0)

pic
Editor guide