Modifying Users in Linux


Modifying Users in Linux

The usermod command is a command in Linux used to change a user's features in the command line. After creating a user, we need to change attributes such as the password or login directory. So we use the usermod command.

Adding a User to a Group

The typical use case of the usermod command is adding a user to the group. Use the –a –G options followed by the group's name and username to add an existing user to a secondary group. If you want to add to multiple groups once, specify each other with the -G option, (commas) interaction without intervention.

Always use the option when adding a user to a new group. If you avoid the -a option, the user will be removed from groups not listed after the -G option. If the user or group does not exist, the command will warn you.

To change the User Primary Group.

To change the user's primary group, call the username command using the -g option -g option to contact the user name and username of the group. Each user is in a primary group and zero or more secondary groups.

To change the User Information.

The full name of the user information can be changed by running the command with the –c option followed by the new comment and username.

To change a User Home Directory.

In most Linux systems, the user home directories were named under the user and created under the / home directory.

To change a User UID

UID (User Identifier) is several users. The operating system uses this to refer to a user. To change the user UID, call the option to follow the new UID and the user.

The UID of the user is located in the user's home directory, and the user's mailbox file will be automatically changed. The ownership of all other files should be automatically adjusted.

To Change a User Name

Although not often, we may want to change the existing user name. Use the username to change the -l option. When you change the username, you may want to change the user's home directory to reflect the new username.

To Lock and Unlock a User Account

The –L option is used to lock a user account. The commands will be added to the encrypted password before the encrypted password exclamation point (!) marks. The password field in the / etc / shadow file contains an exclamation point; using password authentication cannot be logged in to the system. Other login methods such as key-based authentication or switching to the user are still allowed. If we want to lock the account and disable all login methods, you must set up the expiration date 1.