Sunday, December 22, 2024

Top 5 This Week

Related Posts

Usermod Complete Guide 💻

Adding User to Groups

Let’s add irfan to the admins group using:

usermod -aG admins irfan

However, if attempted as irfan, it’ll generate an error. So, first, let’s make irfan a sudo user. Log in as root and execute:


usermod -aG sudo irfan

After adding to the group, verify user groups with:

groups irfan

Now, irfan is a sudo user. Let’s add them to the admin group. First, create the admins group:

sudo groupadd admins

Then, add irfan to the group:

usermod -aG admins irfan

To add irfan to multiple groups, use:

usermod -aG admins,sudo irfan

Verify group addition with:

groups irfan

This user will be effective in the groups, After signing out or the next login.

Changing Home Directory

To change the home directory path for the user irfan:

sudo usermod -d /home/myhome --move-home irfan

Verify changes post-login with:

pwd
echo $HOME

Changing Username

To change irfan’s username to learnwithirfan:

usermod -l learnwithirfan irfan

Verify the change using:

cat /etc/passwd

Managing Account Status

To disable the user account:

usermod -L learnwithirfan

To enable the user account again:

usermod -U learnwithirfan

To set an expiration date for the account:

usermod learnwitirfan -e 2024-12-30

Verify changes using change:

chage -l learnwithirfan

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles