Can somebody please explain to me the exact differences between useradd -b and useradd -d in [Debian] Linux? Both seem to work quite similar to me, but then I spot differences that confuse me.


-b specifies the location of users' home directories. On your average Debian box, this will be /home; you can change the default by editing /etc/default/useradd. useradd will add the new username to this path to get the home directory. This means that if you do

useradd -b /somewhere ian

the new user's directory will be /somewhere/ian.

-d sets the home directory explicitly, irrespective of defaults. So

useradd -d /somewhere-else/ian ian

then the user's home directory will be set to /somewhere-else/ian.

Note that the directory will be set in the password file, but won't actually be created unless -m is also specified (or the CREATE_HOME setting is enabled in the defaults file).

| improve this answer | |
  • 1
    Your explanation is (mostly) correct, but to better stress the difference between the switches, you could have used something other than "ian" as the home directory in the -d example. That's the main point of using -d rather than -b. Also, in the -d example you're missing the username, so that command wouldn't work. – Paulo Almeida Jul 22 '13 at 9:19
  • Oops, I fixed my typo, thanks for pointing it out. – Flup Jul 22 '13 at 9:21
  • In connection with the -m option - the difference between -b and -d is that -d allows to set an actual name, possibly differing from the user's name [e.g. /somewhere/ians_new_home] and that -b creates a new directory with the user's name [/somewhere/ian as you already described :) ]. Using neither -b` nor -d [in connection with -m] will create a new user with a home directory in /home. Could this really have been all that is about that difference? Another case of 'overseen because too obvious?' – erch Jul 23 '13 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.