Score:4

What's the difference between the -d and -m options for useradd?

jp flag

When we use useradd, what is the difference between -d and -m? Because the definitions of both sound similar, which is responsible for creating a home directory.

Score:9
jp flag
Dan

The 2 options are not really similar, but they can work together. If you look at the manpage of useradd you'll find the following:

       -d, --home-dir HOME_DIR
           The new user will be created using HOME_DIR as the value for the user's login
           directory. The default is to append the LOGIN name to BASE_DIR and use that as the
           login directory name. The directory HOME_DIR does not have to exist but will not be
           created if it is missing.

       -m, --create-home
           Create the user's home directory if it does not exist. The files and directories
           contained in the skeleton directory (which can be defined with the -k option) will be
           copied to the home directory.

           By default, if this option is not specified and CREATE_HOME is not enabled, no home
           directories are created.

The -d option is just to set where the home directory of the created user will be but it will not create it if it doesn't exist. While the -m option will create the home directory that is set by -d if it doesn't exist.

jp flag
Dan
Unrelated to your question but, the `useradd` command is a low level command, it is usually [recommended](https://askubuntu.com/q/345974/) to use [`adduser`](https://manpages.ubuntu.com/manpages/hirsute/en/man8/adduser.8.html) instead which is a friendlier frontend for the `useradd` command.
shaunx333 avatar
jp flag
Thanks for the tip, actually Im new to linux and currently learning about System administration.
rexkogitans avatar
cn flag
Not every Linux has `adduser`, e.g. Arch Linux and its derivatives.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.