Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create user accounts named after a domain name. adduser complains that the usernames need to match the NAME_REGEX regular expression.

adduser: Please enter a username matching the regular expression configured
via the NAME_REGEX configuration variable.  Use the `--force-badname'
option to relax this check or reconfigure NAME_REGEX.

I can add the users using useradd without complaint. Is there a reason that I shouldn't modify the regular expression to allow ., - and _?

What characters will cause problems and shouldn't be allowed in usernames?

This is the default NAME_REGEX.

share|improve this question
Note that NAME_REGEX already accepts - as long as it's not the first character. – ringø Sep 3 '15 at 6:02
up vote 21 down vote accepted

My advice to you is to follow the standard recommended by the default NAME_REGEX. You can actually put nearly anything in a user name under *NIX but you may encounter odd problems with library code that makes assumptions. Case in point:

My question to you: do you have a lot of domain names that would collide with each other if you stripped out the unusual punctuation? For example, do you have both "QUALITY-ASSURANCE" and QUALITYASSURANCE" as domain names? If not, you could simply adopt a policy of stripping out the unusual characters and using what's left as the user name.

Also, you could use the "real name" section of the GECOS field in the /etc/passwd information to store the original, unmodified domaain name, and scripts could extract it pretty easily.

share|improve this answer
It is the running into random unexpected bugs part that I'm worried about. I can pretty easily remove the periods and still have no chance of name clashes, but the - could cause a problem. Still it is pretty unlikely. – Ed Haber Oct 9 '09 at 23:28
So the debian system I'm using is using a user www-data. So it looks like - should be ok to be used in usernames. – Ed Haber Oct 13 '09 at 0:36
Actually, that regular expression permits '-' in user names! The first letter needs to be a-z, but subsequent letters of the user names can be '-', a-z, or 0-9. – steveha Oct 13 '09 at 18:22
Ohh! you're right. I missed the extra - when i was looking at it. – Ed Haber Oct 14 '09 at 15:12

More specifically, the POSIX ("Portable Operating System Interface for Unix") standard (IEEE Standard 1003.1 2008) states:

3.431 User Name

A string that is used to identify a user; see also User Database. To be portable across systems conforming to POSIX.1-2008, the value is composed of characters from the portable filename character set. The <hyphen> character should not be used as the first character of a portable user name.

3.278 Portable Filename Character Set

The set of characters from which portable filenames are constructed.

a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 . _ -

Any username that complies with this standard is POSIX-compliant, and ought to be safe.

share|improve this answer
While this is true it's generally frowned upon to have upper-case characters in usernames - people have enough trouble with case-sensitive passwords, and making them have to remember case in their usernames is just kicking them when they're down. (Exception: When your username convention is ALL UPPERCASE CHARACTERS.) – voretaq7 Feb 25 '14 at 21:28

From the NAME_REGEX can be deduced that everything but a through z in upper- and lowercase and the number 0 through 9 would be bad.

share|improve this answer
The word you're looking for is "deduced". – wfaulk Oct 9 '09 at 20:51
So true. :-) Thanks, missed that... – wzzrd Oct 9 '09 at 21:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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