How to set -m option as default in useradd command in linux

Using -m option with useradd command create the user’s home directory . In Debian and Ubuntu when we simply use useradd command without any option bydefault it do not create user’s home directory in /home whereas in CentOS and Red Hat when you use useradd command without any option it creates the user’s home directory in /home.

So here is the question, How can we set the useradd command so that we do not have to use -m option to create user’s home directory in Debian or Ubuntu ?

So first lets see what happen when we do not use -m option with useradd command in Debian or Ubuntu.

Note: The below given command is reference of how you can create home directory by using useradd command.

useradd -m username

See in the screenshot carefully,when I use only useradd command without -m ,the user called joe home directory was not created in /home.
In second command I used “useradd -m” and user called john is created with its home directory in /home.

useradd -m
useradd -m

Follow The Given Below Steps, To Setup By-Default Create User’s Home Directory Option With Useradd Command

Step 1: Edit the line /etc/login.defs file and add the new line “CREATE_HOME yes” .And save and exit

# vi /etc/login.defs

CREATE_HOME  yes

Step 2: Now create a user without using any option and check in /home the user’s home directory will be created there.

Create User:

useradd username

Check User’s Home Directory

ls -l /home

Note:
Or Check in /etc/passwd what is the path of User’s home directory. It might be possible you are trying this practical in already running system and your system admin has set home directory in different path

cat /etc/passwd

or 

grep username /etc/passwd

For eg.

In below given eg. the john has /home/john as user’s home directory

root@tuxworld:~# grep john /etc/passwd
john:x:1011:1011::/home/john:/bin/sh
root@tuxworld:~#

Read Some More Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.