- 1How to Add a New User in Linux
- 2Modify Existing User in Linux
- 3Delete a User in Linux — Step-by-Step for Beginners
- 4Create a User Group in Linux - Step-by-Step Tutorial
- 5Linux: Add User to Group
- 6How to Remove a User from a Group in Linux
- 7Delete a User Group in Linux - Beginner Friendly Tutorial
- 8Linux su Command Tutorial – Switch Users Easily
- 9Linux sudo Command - Execute as Another User
- 10Change a User's Password in Linux Using passwd
- 11Set Password Expiry in Linux using chage
- 12Lock a User Account in Linux
- 13How to Unlock a User Account in Linux
- 14Configure User Login Shell in Linux
- 15How to Configure User Environment Variables in Linux
- 16Edit .bashrc and .profile in Linux - User Startup Files Tutorial
How to Modify an Existing User in Linux
How to Modify an Existing User in Linux
Hey there, welcome to ProgramGuru.org! 👋 Today, we’re going to learn how to modify an existing user in Linux using the usermod
command. If you’ve ever needed to change a username, move the user’s home directory, or update their group—this lesson is for you!
Let’s say we already have a user on our system, and now we want to change some of their details. We’ll walk through the most common modifications step by step.
🔹 1. Change a User’s Username
Let’s change the username from john
to johnny
:
sudo usermod -l johnny john
username 'john' is now changed to 'johnny'
Note: This doesn’t rename the home directory. It just changes the login name.
🔹 2. Rename the User’s Home Directory
If you’ve changed the username, it’s a good idea to rename the home directory too. Here’s how:
sudo usermod -d /home/johnny -m johnny
home directory is now /home/johnny and all files are moved
-d specifies the new home directory and -m moves the files.
🔹 3. Change a User’s Primary Group
Let’s assign the user to a different primary group, say developers
:
sudo usermod -g developers johnny
user 'johnny' is now part of the primary group 'developers'
🔹 4. Add the User to Additional Groups
Want to give the user access to other groups like sudo
or docker
?
sudo usermod -aG sudo,docker johnny
user 'johnny' has been added to groups: sudo, docker
Important: Always use the -a
(append) flag when adding to groups. Without it, the user will be removed from all other groups!
🔹 5. Lock or Unlock a User Account
If you need to temporarily disable a user without deleting them:
sudo usermod -L johnny # Lock
sudo usermod -U johnny # Unlock
account 'johnny' is now locked/unlocked
✅ Summary
Here's what we learned today:
- How to change usernames
- How to move and rename home directories
- How to update primary and secondary groups
- How to lock or unlock accounts
And that’s it! 🎉 You’ve now mastered the basics of modifying users in Linux. Keep practicing and you’ll feel like a pro in no time. Don’t forget to check out the next topic in our Linux course on user permissions.
Thanks for learning with ProgramGuru.org!
Next Topic ⮕Delete a User in Linux — Step-by-Step for Beginners
Comments
Loading comments...