10

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.

9

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.

  • Thanks, works as a charm. Is there any specific reason that -K CREATE_MAIL_SPOOL=no doesn't work at all? – drinchev Jul 11 '13 at 16:44
  • 1
    Because it is not belong to /etc/login.defs. – quanta Jul 11 '13 at 16:50
  • @quanta, For -K MAIL_DIR=/dev/null I got an error: Creating mailbox file: Not a directory – Kirby Oct 19 '16 at 10:23
  • @drinchev, for -K CREATE_MAIL_SPOOL=no I got an error configuration error - unknown item 'CREATE_MAIL_SPOOL' (notify administrator). – Kirby Oct 19 '16 at 10:25
  • I got the same result as Kirby ... I was using it for an alpine docker container so I went with echo "CREATE_MAIL_SPOOL no" >> /etc/default/useradd – Adi Roiban Feb 11 '18 at 15:36
4

I'm setting up a Docker image with Alpine and shadow package and got the same error.

To avoid this "Creating mailbox file: No such file or directory" error I had to add the following inline replacement before trying to add user:

RUN sed -i 's/^CREATE_MAIL_SPOOL=yes/CREATE_MAIL_SPOOL=no/' /etc/default/useradd

This is a Dockerfile directive. If you are struggling with an already running host, just edit the /etc/default/useradd file and change the setting accordingly. This change would prevent any other user creation from getting its mailbox created.
It that is not the desired behavior, you can just create the /var/mail folder with

[ -d /var/mail ] || mkdir /var/mail

Or in the Dockerfile:

RUN mkdir /var/mail 

Hope this helped.

3

Oddly enough, the answer is no. I just read the sourcecode and there is no option for this, though there is a workaround (sort of): maildirs don't get created for system accounts.

So you can do useradd -r -m. You'll have to specify a UID/GID manually as well though, as they're picked from different ranges.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.