10

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?

Sam
  • 1,063
  • Debian has set the underscore as a requirement for usernames who are related with packages. https://www.debian.org/doc/debian-policy/upgrading-checklist.html#version-4-5-0 – rfmoz May 26 '20 at 14:31

3 Answers3

7

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:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/my:user/bin

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

Edit:
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.

wag
  • 35,944
  • 12
  • 67
  • 51
3

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
tmow
  • 1,255
  • 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 'SO- stop being evil' 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 07:53
0

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?

tshepang
  • 65,642
  • 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 'SO- stop being evil' Jan 27 '11 at 19:23