LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-08-2014, 08:42 AM   #1
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Rep: Reputation: Disabled
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
 
Old 12-08-2014, 09:06 AM   #2
JeremyBoden
Member
 
Registered: Nov 2011
Posts: 938

Rep: Reputation: 174Reputation: 174
Try
Code:
man useradd
For Debian (and Ubuntu etc) see
Code:
man adduser
 
Old 12-08-2014, 09:11 AM   #3
wpeckham
Senior Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 1,650

Rep: Reputation: 568Reputation: 568Reputation: 568Reputation: 568Reputation: 568Reputation: 568
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.
 
Old 12-08-2014, 09:19 AM   #4
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Original Poster
Rep: Reputation: Disabled
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.
 
Old 12-08-2014, 09:33 AM   #5
wpeckham
Senior Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 1,650

Rep: Reputation: 568Reputation: 568Reputation: 568Reputation: 568Reputation: 568Reputation: 568
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.

Last edited by wpeckham; 12-08-2014 at 09:35 AM.
 
Old 12-08-2014, 03:28 PM   #6
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Original Poster
Rep: Reputation: Disabled
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.

Last edited by sumncguy; 12-08-2014 at 03:29 PM.
 
Old 12-08-2014, 10:27 PM   #7
wpeckham
Senior Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 1,650

Rep: Reputation: 568Reputation: 568Reputation: 568Reputation: 568Reputation: 568Reputation: 568
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.

Last edited by wpeckham; 12-08-2014 at 10:32 PM.
 
Old 12-09-2014, 07:11 AM   #8
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-09-2014, 07:50 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,600

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
Old 12-09-2014, 09:51 AM   #10
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Original Poster
Rep: Reputation: Disabled
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.

Last edited by sumncguy; 12-09-2014 at 09:53 AM.
 
Old 12-09-2014, 01:51 PM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,600

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mandatory Introduction slackops LinuxQuestions.org Member Intro 2 11-11-2013 08:38 PM
mandatory introduction kalaka LinuxQuestions.org Member Intro 1 01-21-2010 04:20 PM
Mandatory Locking Kernel programmer Linux - Software 3 07-28-2006 06:21 AM
Mandatory Locking Kernel programmer Linux - Kernel 1 07-28-2006 06:10 AM
Useradd - Cannot locate /etc/default/useradd in Solaris Paean Solaris / OpenSolaris 4 12-09-2005 02:36 AM


All times are GMT -5. The time now is 09:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration