I want to know where should I use useradd -m or useradd -d to make a new home directory? I didn't get the purpose of -m and -d flag in useradd?
I'm going to assume you read the manual (
man useradd), which says
--home HOME_DIRThe new user will be created using
HOME_DIRas the value for the user's login directory [...]
--create-homeCreate the user's home directory if it does not exist [...]
As it says, the
--home flag defines the entry in the user database (
--create-home creates the directory.
In a typical single user home environment you'd probably want the
--create-home flag, leaving the other at its default value.