Closed Captioning Closed captioning available on our YouTube channel

How to use the usermod command: 2-Minute Linux Tips

Network World | Nov 27, 2020

In this Linux tip, learn how to use the usermod command. It’s a command that allows you to make a lot of different changes to user accounts without having to edit configuration files.

Copyright © 2020 IDG Communications, Inc.

Similar
Hi, this is Sandra Henry-Stocker, author of the "Unix as a Second Language" blog on NetworkWorld.
In this Linux tip, we’re going to look at the usermod command. It’s a command that allows you to make a lot of different changes to user accounts without having to edit configuration files like /etc/passwd and /etc/group.
To demonstrate how the command works, I’m going to change someone’s username. I’ll change Joe Doe’s username from "jdoe" to "gijoe".
Here’s Joe’s account and his groups:
$ grep oe /etc/passwd; groups jdoe
jdoe:x:1017:1017:Joe Doe:/home/jdoe:/bin/bash
jdoe : jdoe adm
This command changes his username to "gijoe":
New Current
| |
V V
$ sudo usermod -l gijoe jdoe
This command changes the username in the /etc/passwd file and updates the /etc/group file with the new username. To change the home directory to match the new username and change the user’s description fields, I’ll do this:
$ sudo usermod -d /home/gijoe -m gijoe
$ sudo usermod -c "GI Joe" gijoe
To verify that the changes were made:
$ grep gijoe /etc/passwd
gijoe:x:1017:1017:Joe Doe:/home/gijoe:/bin/bash
$ ls -ld ~gijoe
drwxr-xr-x 2 gijoe jdoe 4096 Nov 12 12:12 /home/gijoe
$ groups gijoe
gijoe : jdoe adm
You can’t change users’ groups with usermod unless you’re moving them to an existing group. Otherwise, you would use the groupmod command.
Keep in mind that there are many other types of changes that usermod can help you make -- locking and unlocking accounts and more.
That’s your Linux tip for usermod.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.
Popular
Featured videos from IDG.tv