Modify User in Linux

Modify User in Linux

 Modify User in Linux


Use usermod command to modify/update existing user account in Linux.

Syntax:

$ usermod [options] USER_NAME

Example:

Change the default shell of user myuser to /usr/sbin/nologin. Use -s or –shell to update the default shell.

$ usermod --shell "/usr/sbin/nologin" myuser

Change Home Directory

Use -d or –home switch to change the current home directory of the user. The new directory will create automatically, but the parent directory of the new home must exist.

$ usermod --home "/var/home/myuser" myuser

You can also use -m or –move-home with the above switch to move the content of the home directory as well.

$ usermod --move-home --home "/var/home/myuser" myuser

Lock and Unlock User

Use -L or –lock to lock the specific accounts in the Linux system. Use -U or –unlock to unlock any locked user account under the Linux system.

$ usermod --lock myuser         ## Lock account
$ usermod --unlock myuser       ## Unlock account

Change Primary Group

Use -g or –gid to forcefully change the user’s primary group. For example, set “staff” as the primary group for the myuser account.

$ usermod --gid staff myuser 

Adding User to Secondary Group

Use -G or –groups to add a user in multiple secondary groups. For example add myuser to staff, accounts group.

$ usermod -G staff,accounts myuser 
Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close