useradd -M is creating a home directory

skybird182

New Member
Joined
Mar 25, 2021
Messages
3
Reaction score
0
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.

svr@svr-2004:~$ sudo useradd -M test_acct
svr@svr-2004:~$ grep test_acct /etc/passwd
test_acct:x:1004:1004::/home/test_acct:/bin/sh
svr@svr-2004:~$

from /etc/logins.def

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


Can you try:

Code:
adduser --no-create-home

The useradd has been supplanted/depreciated (as far as my memory says). It may not work because there's a newer tool and there could be some conflict between the two.
 
I switched to adduser. The home account is still created.
root@svr-2004:~# 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.
root@svr-2004:/# grep junk /etc/passwd
flyboy:x:1003:1003::/junk:/bin/sh
junk_acct:x:1004:1004:,,,:/home/junk_acct:/bin/bash
root@svr-2004:/#

After further investigation I discovered this:
root@svr-2004:/# su junk_acct
junk_acct@svr-2004:/$ ls
bin boot cdrom dev etc home (abbreviated list)
junk_acct@svr-2004:/$ cd home
junk_acct@svr-2004:/home$ pwd
/home

junk_acct@svr-2004:/$ cd junk
bash: cd: junk: No such file or directory
junk_acct@svr-2004:/$

Is /etc/passwd creating a phantom directory ?
 
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.
 

Members online


Top