Linux – How to create linux account with useradd without creating mail spool

linuxuser-accounts

Summary

Can I create a new user without creating mail spool and without modification of /etc/default/useradd ?

Explaination

I want to create a user that has a home directory and skeletion, but I don't want the useradd script to add a mail spool file to the unix system.

My /etc/default/useradd file states that

CREATE_MAIL_SPOOL=yes

but I don't want to modify the default behaviour.

For now I'm using

useradd nomailuser
rm /var/spool/mail/nomailuser

Also I know about -d but it seems that I can't find an option for not creating a mail spool.

I'm thinking about is there an option to use custom /etc/default/useradd file.

Best Answer

man useradd

   -K, --key KEY=VALUE
       Overrides /etc/login.defs defaults (UID_MIN, UID_MAX, UMASK, PASS_MAX_DAYS and others).

       Example: -K PASS_MAX_DAYS=-1 can be used when creating system account to turn off password ageing, even though
       system account has no password at all. Multiple -K options can be specified, e.g.: -K UID_MIN=100 -K UID_MAX=499

So, try this:

# useradd -K MAIL_DIR=/dev/null nomailuser

A warning would appear (Creating mailbox file: Not a directory), but you can ignore.