LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   When using useradd - is -d mandatory (https://www.linuxquestions.org/questions/linux-newbie-8/when-using-useradd-is-d-mandatory-4175527676/)

sumncguy 12-08-2014 07:42 AM

When using useradd - is -d mandatory
 
if I do

useradd mary

In the related /etc files, I see /home/mary as the new users home directory.

However, when I lookin /home I do not see mary subdir.

Is -d mandatory when using useradd ?

Checked on 2 distros
Linux a3013-desktop 3.11.0-26-generic #45-Ubuntu SMP Tue Jul 15 04:04:15 UTC 2014 i686 i686 i686 GNU/Linux

and

Linux localhost 3.15.6+ #2 Centos SMP Wed Jul 23 01:26:02 UTC 2014 x86_64 x86_64 x86_64
GNU/Linux


Tks in advance

JeremyBoden 12-08-2014 08:06 AM

Try
Code:

man useradd
For Debian (and Ubuntu etc) see
Code:

man adduser

wpeckham 12-08-2014 08:11 AM

useradd
 
May I ask if you looked in the man page for useradd?

On my machine -d forces the home name and creation. There are default location and action for these, but you can force the behvior you need. Generally, if the default location is fine, you can force creation of the folder with the -m option without using the -d option.

Note that the man page, options, defaults, and application behavior are somewhat version and distribution specific. If in doubt, check the man page for useradd on YOUR machine. Also know that the gui tools can either use, or bypass, the useradd functions. I always prefer and trust the commands over the gui tools, but not everyone will agree.

sumncguy 12-08-2014 08:19 AM

According to my tests, adduser will indeed create the new users /home/<user> login directory. That command, if Im not mistaken is an add on.

In addition, I already looked in man and info and there is no definitive statement that says -d is or isnt mandatory when using useradd.

Quote:

-d, --home 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.

I also see that I can edit /etc/login.defs .. still this doesnt answer the question.

If Im asked a question on the cert "Does useradd create /home/$USER by default ?" It looks like the answer is no.

wpeckham 12-08-2014 08:33 AM

useradd and adduser
 
OK, you are not understanding. Also, you stop reading too early in the page.

The default path and creation behavior are CONFIGURABLE. Different distros and versions MAY have different behaviors, you over-ride the defaults to get exactly the behavior you wish using the command-line parameters. The -d option is NOT required, but if you want to force home folder creation then either -d or -m should do the job for you. -d also requires the home folder path, -m uses the default for your system. If you change the defaults to the behavior you need, then you will not require ANY command-line parameter other than the new user name.

sumncguy 12-08-2014 02:28 PM

My initial question still isnt answered .. I understand that default directory is configurable. Thats not what Im asking.

I am asking ... if I am asked on a cert, "Does useradd create /home/$USER by default ?", what is the correct answer.

I really didnt want to get too far into this .. Im attending a Linux Essentials class. adduser is irrelevent for this particular situation. Thats a front end that is not part of the Essential content.

This exact question came up on a quiz ... "Does useradd create /home/$USER by default ?" True or False. I answered False.
and was marked wrong.

I answered False, because without the "-d" argurment, /home/$USER is NOT created BY DEFAULT. Only when I use the "-d" is the home directory defined.

wpeckham 12-08-2014 09:27 PM

Without knowing more about the class and the background, I cannot say it was a poorly thought question. But....

I am a system administrator. I routinly change the behavior of such programs. They are configurable specifically so you CAN. In different distributions the home folder may default to /home or /usr/home or other locations, but you can change that. You can change the skel, the base pattern for the home folder (the default contents of the initial home), and you can change the CREATION behvior to default to create the folder or to NOT create the folder unless told with -d or -m.

In other words, the behavior on install depends upon the defaults set by the distribution maintainers. The behavior may be changed later by whoever maintains the system.

Unless you specify a particular distribution, and perhaps even a particular release of that version, and specify that it has not been changed since installation, the answer is "it depends"!

What you can ALWAYS do is to over-ride the defaults to get exactly the behavior you wish. If you need to force creation AND a different than default home path, you need -d. If you only need to force creation of the home folder and the default is fine, you might use -m.

In the class or environment that you were asked that question, were you specifically targeting a certain distribution? Specifying the distribution MAY allow a more determanent answer.

sumncguy 12-09-2014 06:11 AM

Yes. Some of the course material is questionable. The community college is using netacad.com. Terrible. They have a boat load of issues with the context of the essentials class. .. so bad that Ive been keeping a log so that I can provide a critique of the class material.

At any rate, I was playing around at home last night ... and the only way I was able to get a /home/mary created with useradd was to use the -m switch, which coincidentally is not part of the essentials curriculum. My install is a default install with no modification to any config files.

When I get home, Ill capture lsb_release -a info on my single user Ubuntu 14.04 LTS box and the same from the classes Centos VM.

Appreciate the help !

Thanks
Chris

jpollard 12-09-2014 06:50 AM

The correct answer (as in nearly any system administration question) is "It depends".

And just because you don't change any "defaults" after install doesn't mean the "defaults" are the same on all systems.

It depends on the distribution, and even what release of that distribution.

One reason for the various defaults is that they can depend on site security policies. Some will not allow a login if the users home directory doesn't exist. Others allow login, but if the home directory doesn't exist then it uses /, or even /tmp. Others allow login, but create the home directory on the first login.

The ONLY way to handle all of those variations is to have defaults - that match the site. That doesn't mean they match the distribution.

sumncguy 12-09-2014 08:51 AM

Well fellas .. unfortunately "it depends" wasnt an option on the quiz. And I understand that the real world may differ from the classroom environment. Ive been a Network Engineer since 1981.

However ..

I went ahead into the next chapter which covers some of the items you guys discussed .. /etc/login.defs, /etc/default/useradd ...

But the initial question was pretty specific .. that is "by default" ... what you see below is the exact text given in the next chapter of the course material.

Quote:


home directory: By default, most distributions will create the user's home directory with the same name as the user account underneath the /home. For example, if creating a user account named "sam", the user's new home directory would be /home/sam. There are several options for the useradd command that can affect creating the user's home directory:

The -b option allows you to specify a different directory under which the user's home directory will be created. For example: -b /test would result in a home directory of /test/sam for a user account named "sam".
The -d option allows you to specify either an existing directory or a new home directory to create for the user. This should be a full path for the user's home directory. For example: -d /home/sam
The -m option tells useradd to create the home directory; is not normally needed as this is the default behavior of the useradd command. However, when using the -k option (see below) to specify a different skeleton directory, then the -m option is needed.
The -M option is used to specify to the useradd command that it should not create the home directory

... which according to what I'm finding through testing in two separate distros .. Ubuntu and Centos ... at least one or two of the statements above are incorrect.

jpollard 12-09-2014 12:51 PM

As I said, it depends.

The controls on -m are determined from the defaults configured... And different distributions can have different distributions. "not normally needed" is specifically stating it varies.


All times are GMT -5. The time now is 05:13 AM.