useradd -M is creating a home directory

skybird182

New Member
Credits
34
It appears the -M / --no-create-home switch does not prevent the creation of the home directory as can be seen in the command line text below.
The useradd man page clearly states the following:
-M, --no-create-home Do not create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes.

Is this a bug ? Am I missing something ? I am using xubuntu 20.04 LTS

In the /etc/login.defs I could only fine CREATE_HOME and not DEFAULT_HOME.

[email protected]:~$ sudo useradd -M test_acct
[email protected]:~$ grep test_acct /etc/passwd
test_acct:x:1004:1004::/home/test_acct:/bin/sh
[email protected]:~$

from /etc/logins.def

# Should login be allowed if we can't cd to the home directory?
# Default in no.
#
DEFAULT_HOME yes
 


skybird182

New Member
Credits
34
I switched to adduser. The home account is still created.
[email protected]:~# adduser --no-create-home junk_acct
Adding user `junk_acct' ...
Adding new group `junk_acct' (1004) ...
Adding new user `junk_acct' (1004) with group `junk_acct' ...
Not creating home directory `/home/junk_acct'.

The account is still created.
[email protected]:/# grep junk /etc/passwd
flyboy:x:1003:1003::/junk:/bin/sh
junk_acct:x:1004:1004:,,,:/home/junk_acct:/bin/bash
[email protected]:/#

After further investigation I discovered this:
[email protected]:/# su junk_acct
[email protected]:/$ ls
bin boot cdrom dev etc home (abbreviated list)
[email protected]:/$ cd home
[email protected]:/home$ pwd
/home

[email protected]:/$ cd junk
bash: cd: junk: No such file or directory
[email protected]:/$

Is /etc/passwd creating a phantom directory ?
 

KGIII

Super Moderator
Staff member
Gold Supporter
Credits
28,038
Is /etc/passwd creating a phantom directory
So it seems. I finally decided to check and I get the same behavior with an Ubuntu VM. But, if I look at /home, I do not see my 'testing' user's /home/testing account.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!


Top