Failed to save user : Usernames cannot begin with a number

I am testing virtualmin as a possible replacement for an existing mail server. One issue that I have found along the way is that I have a few email addresses which begin with a number (a couple are all numbers) and virtualmin will not create them. I can force the issue at the command line like this:

useradd 123cheese.com -g 1244 -c “cheese.com” -d /home/cheese.com -s /bin/bash

And get an entry that looks identical in the /etc/passwd file as far as the group and such go, but in virtualmin this user turns up as “User is temporarily disabled” and as having “Login Access” of “None”. I can set it to any of the other options but “Email” never appears when I return to the menu.

Is there a workaround for this?

SYSTEM INFORMATION
OS type and version Ubuntu Linux 24.04
Virtualmin version 7.20.2

I thought anything that complies with the RFC6532 spec applied but doesn’t that mean enclosing such number starting chars in quotes "? so "123user name@domain.com"

I think this came up before? It is a Linux user issue. It looks like there is some support in RHEL for it now though.

–user “3cheese@cheese.com” got me “Usernames cannot begin with a number” with virtualmin -create-user

Doing “2cheese” in the web interface created a mail user but it does not recognize the credentials if I login as 2cheese@cheese.com. If I login as "2cheese"@cheese.com it does authenticate but results in errors in the web mail interface.

Try this

  • create and email address with a user name of eg cheese if required, but the virtual server owner will already have this setup
  • disable the primary email address on this user
  • add an alias with the required email address.

This is a workaround, but should help.

I believe that I have come up with a workaround (though I haven’t fully tested an account with a client yet, telnet tests work). It’s a bit of a pain though.

(These commands imply that you have done “sudo -i”, if not you can put sudo in front of most of them. They also imply that the domain has been made, in the example “cheese.com” and that the user you want to create is 1234@cheese.com, adjust accordingly.)

First, create a temporary mail user that does not start with a number (this is for easily copying the folder structure and settings, it can be deleted when we are done) either with the web interface or:

virtualmin create-user --domain cheese.com --user emptyuser --random-pass --shell /dev/null

Next determine the group (and directory and shell) that this temporary user went into:

tail -1 /etc/passwd

Example (the group here is 1258, the directory is /home/cheese.com/homes/emptyuser and the shell is /dev/null):

emptyuser@cheese.com:x:1778:1258::/home/cheese.com/homes/emptyuser:/dev/null

Now create your new user at the command line using the same group and shell and similar “part before the @” directory:

useradd 1234@cheese.com -g 1258 -d /home/cheese.com/homes/1234 -s /dev/null

(Don’t worry when it says “useradd: Warning: missing or non-executable shell ‘/dev/null’”)

And copy the structure from your empty user to it (this will make the 1234 directory and populate it):

cp -r /home/cheese.com/homes/emptyuser /home/cheese.com/homes/1234

Check the ownership of the emptyuser folder:

ls -alt /home/cheese.com/homes/emptyuser

Example:

total 16
drwx------ 9 emptyuser@cheese.com cheese.com 4096 Aug 8 16:06 Maildir

(etc)

And change your copied version to match your user:

chown -R 1234@cheese.com:cheese.com /home/cheese.com/homes/1234

(Note that the email address and group are separated by a colon in the command but a space in the file, -R will do this recursively through your new user’s new folders.)

Now add your user to /etc/postfix/virtual in the same format as the others and save. For example:

tail -1 /etc/postfix/virtual

emptyuser@cheese.com emptyuser\@cheese.com

Note the “\” on the second instance of the mail user lines (it’s not on the domain user lines, don’t be confused, you want it). I used nano, but your editor is your choice:

nano /etc/postfix/virtual

So ended up with:

1234@cheese.com 1234\@cheese.com

(I am not sure if it matters but I used tab to separate the two since the file’s spacing implied that for the others.)

Now update postmap and restart postfix and dovecot:

postmap /etc/postfix/virtual
systemctl reload postfix
systemctl reload dovecot

Now go into your virtualmin and navigate to the domain and Edit Users. Click the user, set the password and mail permissions and quota (if needed) and uncheck “Login temporarily disabled”, and Save.

You should now be able to delete your emptyuser if desired, either with the web interface or:

virtualmin delete-user --domain cheese.com --user emptyuser --random-pass --shell /dev/null

Does anyone know if this misses anything that Virtualmin does with non-number-starts-with-a-number email accounts?

If I am right that this works and does everything then it would seem that all-number or starts-with-a-number email addresses do not cause problems in Linux postfix or dovecot and are not an issue for email. Is there then some way that I can submit a feature request that Virtualmin deal with them natively? This seems like a lot of steps if Virtualmin is the only thing that legitimately does not like these.

1 Like

Just for completeness you can also:

virtualmin modify-user --domain the-domain.com --user the@emailaddress.com --new-pass “the-password” --enable --quota some-big-number

To enable the user, change the password, and set the quota (which I had you doing in the web interface before). The quota is in kb, so --quota 10485760 is 10GB (etc).

Email users are also system users. They must comply with all the requirements of both.

Since email addresses can definitely begin with a number, that would leave a system requirement, but if it’s a system requirement, why would:

work?

found this articel, it is a bit above my head but says why you cant start usernames (or shouldn’t) in linux

Why Can’t Linux Usernames Start With Numbers? | Baeldung

1 Like

Sure I could see that sort of thing for a programming, software installing user, but for a Virtualmin email user (though I can’t think of anything else that Virtualmin does natively that should matter), none of the functions needed have a problem with it.

Webmin, for example, has no problem adding an all-number user… so the check for this doesn’t happen at that level. It doesn’t happen at the useradd level, as demonstrated. At least in modern Ubuntu it might be time to remove the check for Virtualmin (perhaps with a “you might need to do something someday that doesn’t work with this” warning).