C5 & C6 : Useradd

Home » CentOS » C5 & C6 : Useradd
CentOS 4 Comments

useradd –help

-d, –home-dir HOME_DIR home directory for the new user account
-M, do not create user’s home directory yet
useradd -M -s /sbin/nologin FRED

produces in /etc/passwd

fred:x:504:504::/home/fred:/sbin/nologin

Trying again with

useradd -d /dev/null -s /sbin/nologin doris

gives a CLI message

useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.

and in /etc/password

doris:x:505:505::/dev/null:/sbin/nologin

QUESTION

What is the ‘official’ method of creating a user with no home directory and no log-on ability ?

Thank you.

4 thoughts on - C5 & C6 : Useradd

  • Your first invocation seemed to look fine. What result do you expect to get? Every user needs a home directory in /etc/passwd even if it doesn’t exist.

    Regards,
    Dennis

  • Guten Morgen Denis,

    Aber/But …..

    -M, do not create user’s home directory

    so why do I see in /etc/passwd

    fred:x:504:504::/home/fred:/sbin/nologin

    Should the ‘correct’ entry be:-

    fred:x:504:504:::/sbin/nologin ?

    OK, I can use -d /nix but what should -M actually do ?

  • Interesting. I’m usually putting slightly more effort in creation of such users. I do create them with regular command

    /usr/sbin/useradd -s /sbin/nologin -c “Whatever user or something” whatever
    /usr/sbin/usermod -d /var/nonexistent whatever
    /bin/rm -rf /home/whatever
    /bin/rm -f /var/spool/mail/whatever

    (I made sure once /var/whatever does not exist).

    I wonder, under which circumstances pointing to /dev/null as to such user’s home directory is preferable compared to pointing to place that doesn’t exist on file system.

    I don’t know where I picked up a habit pointing to nonexistent place as home directory for such user. I do know though why I type the whole path beginning with leading slash for commands I execute as almighty user root
    ;-)

    Valeri

    ++++++++++++++++++++++++++++++++++++++++
    Valeri Galtsev Sr System Administrator Department of Astronomy and Astrophysics Kavli Institute for Cosmological Physics University of Chicago Phone: 773-702-4247
    ++++++++++++++++++++++++++++++++++++++++

  • You can add the -M option too which should get rid of the warning messages (though I have not tested this).

    Regards,
    Dennis

Leave a Reply to Always Learning Cancel reply