

DEBIAN BUSTER WHICH PACKAGE USERMOD HOW TO
Number of days of warning before password expires : 7 How to Change a User’s Shell with usermod Maximum number of days between password change : 99999 Minimum number of days between password change : 0 In the above example, the example-user user account automatically deactivates on July 30, 2021. Ensure you replace example-user with your own user. To set an expiration date for a user’s account, use the example command. sudo cat /etc/shadow | grep example-userĮxample-user:: How to Set an Expiration Date for a User’s Account with usermod Now the entry for example-user in the /etc/shadow file should lose its exclamation point. To unlock a user’s account, use the -U option. sudo cat /etc/shadow | grep example-userĮxample-user:!: Unlocking a User’s Account with usermod The example below displays what an entry for example-user may look like. Locked users display with an exclamation point after their login names, right at the start of their encrypted passwords, in the /etc/shadow file. To lock a user’s account, use the -L option. Locking an account allows you to prevent logins on it without completely removing the account. You can lock and unlock user accounts with usermod. id: ‘example-user’: no such user How to Lock and Unlock a User’s Account with usermod Running the sudo id example-user command should now output an error since the user’s login name has changed. Reference the previous section if you want to change the user’s home directory to match its login name. Usermod allows you to change a user’s login name with the -l option, for example: sudo usermod -l new-example-user example-userĬhanging a user’s login name does not change the name of that user’s home directory. home/example-user-new-home How to Change a User’s Login Name with usermod You can verify the change by echoing the user’s home directory. sudo usermod -home /home/example-user-new-home -move-home example-user You can add the -move-home option to also have the contents of the user’s existing home directory moved to the new directory. sudo usermod -d /home/example-user-new-home example-user Use the -d option to change the user’s home directory. uid=1001(example-user) gid=1002(example-group) groups=1002(example-group),1003(groupA),1004(groupB),1005(groupC) How do I Use usermod to Change a User’s Home Directory? Without it (using only the -G option) the user gets removed from any supplementary groups that are not listed in the command.īelow is an example of what the user’s id information may look like after the command above is executed. The -a option is used to have these groups appended to the user’s list of supplementary groups. This option can assign multiple groups at once, separating each with a comma (no space): sudo usermod -aG groupA,groupB,groupC example-user

To assign a user to one or more supplementary groups, use the -aG option. How to Add a User to a Group with usermod The Linux user group must exist before usermod allows you to assign a user to the groups. Take a look at the results with the id command. Here is an example: sudo usermod -g example-group example-user You can use usermod to change a user’s primary group with the -g option. Using usermod to Add a User to a Group How to Change a User’s Primary Group with usermod Learn more about what chmod is and how to use it in our guide Modify File Permissions with chmod. For instance, while usermod allows you to change a user’s home directory, chmod lets you give a file in that directory executable permissions. But where usermod modifies settings for an existing user, chmod modifies the permissions on a given file or directory. On the other hand, chmod, like usermod, modifies existing resources.

See our Linux Users and Groups guide for more on the useradd command. While useradd can define a Linux user’s settings, it does so for new users, not existing users. The difference between useradd and usermod is that the former is used for creating new users and the latter is used for modifying existing users. This guide covers how the usermod utility works, and how it relates to other Linux commands. In addition, usermod can add a user to supplementary Linux groups, lock and unlock a user’s account, and more. Most things that get set up when you create a user - from a login name and home directory to the shell environment - can be altered using usermod. The usermod command lets you change an existing Linux user’s settings. What is usermod? Tool Used to Modify a User’s Linux Settings
