User Management in Linux (whoami, who, w, id, su, sudo, useradd, passed, change, usermod, groupmod, groupdel) - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

User Management in Linux (whoami, who, w, id, su, sudo, useradd, passed, change, usermod, groupmod, groupdel)

Share This

whoami command

We know that Linux is a multi-user system. If more than one person uses a single system, then everyone should have their own user account. Hence, if you want to know the user account details. You can run whoami command. This command displays the information about the current user only.


who command

The who command gives the information about the users logged on to the system.


w command

The command w tells about the users who are logged in and what they are doing.


id command

The command id tells about your user id, primary group id, and a list of groups that belongs to you.


su command

The su command allows you to run a shell as another user. You can use su username.

You can change the user to root using su root when you know the root password.

The root user can become any existing user using su - username without knowing that user's password. Otherwise, a password is needed.

By default, the su command maintains the same shell environment. To access the target user's shell environment, use the su command with (-) followed by the target user name.

If any user name is not mentioned like su - then by default, it will assume root as the target user.


sudo command

The sudo command allows a user to start programs with the credentials of another user.


Adding a user

As a root user, you can try useradd username to create a new user.

With sudo command we're allowed to create new users on the system by sudo useradd -m username command without becoming root or without knowing the root password.

By typing sudo su - a user can become root user without typing the password for root. The sudo command will ask for the user's own password.

In Linux, user management includes everything from creating a user to deleting a user on your system. User management can be done in three ways on a Linux system.

  • 1. Graphical tools are easy and suitable for new users, as it makes sure you'll not run into any trouble.
  • 2. Command line tools include commands like useradd, userdel, passwd, etc. These are mostly used by server administrators.
  • 3. Third and very rare tool is to edit the local configuration files in /etc/password directory using vi.

The root user is the superuser and has all the powers for creating a user, deleting a user, and can even login in with the other user's account. The root user always has userid 0.

With useradd commands you can add a user, as shown below:.

useradd -m -d /home/userName -c "userName" userName 

To delete a user account userdel command is used as userdel -r userName.

The command usermod is used to modify the properties of an existing user. This command can be used like usermod -c <'newName'> <oldName> .

By using userdel -r userName, you can delete the home directory along with the user account.


Linux User Password

You can change your password by using passwd command.

A user can set the password with the command passwd. The old password has to be typed twice before entering the new one.

Passwords are stored in shadow files which are kept in /etc/shadow directory.

This file is a read-only directory and can be read only by the root.


chage command

The chage command can be used by a user to know the information about their password. The -l option is used to list the information.

chage -l <userName>

Linux Groups

Users can be listed in different groups. Group allows us to set permission on the group level instead of setting the permission on an individual level.

Every Linux distribution has a graphical tool to manage groups. Groups can be managed by graphical tools, command line tools, and by vi or vigr depending upon the user's experience. Only experienced users should use vi or vigr to manage groups since it will do proper locking or changes in the file.

The groupadd command creates or adds a group in our system.

The /etc/group file defines the group membership. A user can be a member of more than one group.

The group command tells about the group where the current user belongs to.

The group members can be edited with usermod or useradd command. If a group is not listed then by default, usermod command will remove the user from every group of which he is a member. Here, -a (append) option is used to prevent this from happening.

 usermod -a -G <group> <userName>

With the help of groupmod command you can change the name of an already existing group.

 groupmod -n <oldGroup> <newGroup>

The command groupdel will delete a group permanently from the system.



Happy Exploring!

No comments:

Post a Comment