Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

So why has the underscore been considered a bad character for user names in Debian (and possibly other distributions) while it has been removed from adduser's NAME_REGEX in Ubuntu?

share|improve this question

POSIX specifies the usage of a portable set of characters for user and group names.
_ - . are allowed characters, NAME_REGEX checks if the username does only contain specified characters. The distribution developers define, if further characters are denied. Ubuntu, for example, does forbid the use of . by default.

Adding this restriction avoids interference with other system tools, which may interpret special characters. Think of the variable $PATH, when you have a user with the name my:user and add your home directory to $PATH:


The directories /home/my and user/bin would (probably) not exist. Further, /etc/passwd would have two : more than needed.

Debian's adduser (version 3.110) uses /^[_.A-Za-z0-9][-\@_.A-Za-z0-9]*\$?$/ for checking usernames, _ is allowed as long as NAME_REGEX does not forbid it.

share|improve this answer
But the question was about _ not :... – Josh Jan 27 '11 at 13:13
Isn't the @ also allowed in posix, at least according to adduser – Sam Jan 27 '11 at 13:16
And yeah while that explains why you shouldn't allow : it doesn't explain why _ is bad. – Sam Jan 27 '11 at 13:17
_ is allowed by default, see the edit. I gave an example of the forbidden character : to show the possible problems with it. – wag Jan 27 '11 at 13:48

A similar question has already been answered here

Theoretically you can use almost any ASCII character you want as username, but, to avoid some kind of bugs, like to one mentioned in the above article, you can set that regular expression that avoid certain issues.

I hope it helps...

share|improve this answer
You won't be able to use :, a newline or a null character in a user name even if you edit /etc/passwd (or most other user databases) by hand. – Gilles Jan 27 '11 at 19:22
@Gilles yes you right, I corrected the answer, but the underscore is fine, to answer to the question the NAME_REGEX is there to prevent some kind of bugs, but it's not set as default because normally some of these chars are allowed. – tmow Jan 28 '11 at 7:53

I'm using Debian Squeeze and I managed to create a user with underscore, adduser user_1. Why do you say they are not allowed?

share|improve this answer
Maybe I have misinterpreted it. I just remembered editing /etc/adduser.conf on a Debian server and the NAME_REGEX (ie the disallowed name regex) contained an underscore. It was commented there however, but I guess I assumed that it represented the default NAME_REGEX. – Sam Jan 27 '11 at 11:45
NAME_REGEX is the allowed name regex, not the disallowed name regex... i.e. if a name matches NAME_REGEX then it is valid. – Josh Jan 27 '11 at 13:20
Debian lenny (stable as I write) doesn't have NAME_REGEX in /etc/adduser.conf, and the built-in default forbids _. – Gilles Jan 27 '11 at 19:23

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.