Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.
-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
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.
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.
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.
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.
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.
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.
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.
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.