The "usermod" command uses full guidance---15 practice routines screenshot

Source: Internet
Author: User
Tags account security
the "usermod" command uses full guidance---15 practice routines screenshot

by Babin Lonston Under:linux Commands On:november 11, 2014

Translation: by Smallliu

In Unix/linux distributions, ' usermod ' is often used by the command line to revise and change any attributes of an existing user. ' The Usermod ' command is similar to ' useradd ' and ' adduser ', but ' usermod ' can only be used for existing users.

Usermod Command Examples

' Useradd ' and ' adduser ' are used to create users in the Linux operating system. To learn more about how to create system users, read the following guidelines: "Useradd" full guide:

After creating the user account, in some cases we need to change the properties of the existing user account. For example, change the user's home directory, login name, login shell, password expiration time, wait, in this case ' usermod ' will be useful.

When we use the ' usermod ' command at the terminal, the following related files will be affected by the execution of the command. /etc/passwd– user account information file. /etc/shadow– user account security file. /etc/group– group information file. /etc/gshadow– group security files. /etc/login.defs– set user account limit file.

Basic syntax for commands:

usermod [Options] Username
RequiredThis command can only be used for existing user accounts only Superuser can execute this command this command applies to any Linux distribution you must understand the role of the command options options for the ' usermod ' command

The ' usermod ' command is simple to use and lots of options to make changes to a existing user. Let us usermod command by modifying some existing users in Linux box with the help of following options.

The rich options for the ' usermod ' command can easily change the properties of an existing user. With the help of the following command options we will witness how to modify existing user properties using the usermod command. -C = Modify the memo information for the user account. -D = modifies the directory where the user is logged on. -E = Change the expiration date of the account. -G = Modify the group to which the user belongs. -G = Modify the additional group to which the user belongs. -L = Modify user account name. -L = Lock user password to invalidate password. -M = Move the contents of an existing home directory to the new directory-P = Modify the user account password (unsafe). -S = Specify user shell. -U = Modify User ID. -U = unlock.

In this article we'll usermod commands with their practical examples and usage in Linux, which Learn and enhance your command-line skills using these options.

In this article you will see practical examples of 15 usermod commands and their use in Linux, which can help you learn and improve the skills of using this command option 1. Add comments for user account

The '-C ' option is used to set a brief comment (information) about the user account. For example, let ' s add information on ' tecmint ' user, using the following command.

The '-C ' option is often used to make a concise note of the user account. For example, for example, we add a note to the ' tecmint ' user using the following command.

# usermod-c ' This is Tecmint ' Tecmint

After adding a note to the user account, the corresponding information is added to the/ect/passwd.

# grep-e--color ' tecmint '/etc/passwd

tecmint:x:500:500:this is tecmint:/home/tecmint:/bin/sh

ADD information to User 2. Change the user's home directory

In the steps above we can see that our home directory is under/home/tecmint/, and if we need to change the directory to another directory we need to use the command-line option '-d '

For example, we would like to change the owner directory to/var/www/, and before that we need to check the user's current home directory with the following command

# grep-e--color '/home/tecmint '/etc/passwd

tecmint:x:500:500:this is tecmint:/home/tecmint:/bin/sh

Now, the following command will change the list of heads of household from/home/tecmint to/var/www/. We still need to confirm that the user's home directory is changed

# usermod-d/var/www/tecmint
# grep-e--color '/var/www/'/etc/passwd

tecmint:x:500:500:this is Tecmint:/var/w Ww:/bin/sh

change user Home Directory 3. Set the username expiration date

The '-e ' option is used to set the expiration date for the user account (the date format is YYYY-MM-DD). Before we do that, let's use the ' chage ' command to find out the current account expiration time.

# chage-l tecmint

Password change					: Nov, 2014 password expires					: never
password inactive
  
   : Never account
expires						: Dec, 2014 Minimum number of days
between password change		: 0
Maximum nu Mber of between password change: 99999 number of days of
warning before password expires	: 7

  

The expiry status of a ' tecmint ' User is Dec 1 2014, let's change it to Nov 1 2014 using ' usermod-e ' option and confirm t He expiry date with ' chage ' command.

The user ' Tecmint ' account expires at Dec 1 2014 and now uses ' usermod-e ' to change it to Nov 1 2014 and to use the ' chage ' command to confirm the change.

# usermod-e 2014-11-01 tecmint
# chage-l Tecmint last

password change					: Nov, 2014
password expires
  : Never
Password inactive					: Never account
expires						: Nov, 2014 Minimum number of days
between pass Word change		: 0 Maximum number of days between password change: 99999 number of days of
warning befor E Password expires	: 7

Set user account Expiry Date 4. Change user Main group

To set or change the user's main group, we use the '-G ' option of the Usermod command, before which we should first confirm that the user's current group is Tecmint_test

# ID tecmint_test

uid=501 (tecmint_test) gid=502 (tecmint_test) groups=502 (tecmint_test)

Like home, change the main group to Babin and confirm the basis changed

# usermod-g Babin tecmint_test
# ID tecmint_test

uid=501 (tecmint_test) gid=502 (Babin) groups=502 (tecmint_test )

change User Primary group 5. Attach groups to existing users

If you want to add a new group named Tecmint_test () to the Tecmint user, you can use the '-G ' option of the Usermod command.

# usermod-g tecmint_test0 tecmint
# ID Tecmint

Add Group to User

Note: Beware that adding a new group to an existing user by simply using the '-G ' option will remove the existing group that the user belongs to. So use the '-a ' and ' g ' option to add new groups to the user. 6. Adding supplementary and Primary Group to User

If you need to add an additional group, you can use the '-a ' and '-g ' option. For example, now add an additional group for tecmint_test () Wheeluser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.