Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

Is there a technical reason why? Is this an artifact from the early days of Linux or Unix, and if so is there a reason why it persists?

share|improve this question
16  
Since this was debunked in the answers, what's your source for this statement? – l0b0 yesterday
8  
@l0b0 - per useradd (from shadow-utils 4.2.1) manual page (see CAVEATS ): Usernames must start with a lower case letter or an underscore [...] In regular expression terms: [a-z_][a-z0-9_-]*[$]? – don_crissti yesterday
14  
@l0b0 - oh, and just because one distro (famous for this kind of things) allows it doesn't mean "it was debunked in the answers". The question is tagged linux, not ubuntu. Try doing it on archlinux. – don_crissti yesterday
1  
@don_crissti It clearly doesn't apply to all Linux distros, and therefore it was interesting to know where that restriction would come from. – l0b0 23 hours ago
2  
Even Ubuntu cares: when you install with the Live CD/Ubiquity your username "Must start with a lower-case letter" – 43Tesseracts 21 hours ago
up vote 68 down vote accepted

Some commands (eg chown) can accept either a username or a numeric user ID, so allowing all-numeric usernames would break that.

A rule to allow names that start with a number and contain some alpha was probably considered not worth the effort; instead there is just a requirement to start with an alpha character.

Edit:

It appears from the other responses that some distro's have subverted this limitation; it worries me to think what might happen on those distros if one ran:

$ useradd 1000   # on most systems this will fail with:
                 # useradd: invalid user name '1000'
$ mkdir /home/1000
$ chown -R 1000 /home/1000   # does this map to username '1000' or UID 1000?

Adding a user named '0' would just be asking for trouble (UID 0 == root user)

share|improve this answer
5  
This is the only post that actually does answer the question. You should add an example to show people that on linux distros that don't have the habit to mutilate upstream code the result of running useradd 253 is useradd: invalid user name '253' – don_crissti yesterday
1  
For the record here is the source code if you want to add it to your post. – don_crissti 20 hours ago
1  
Can you imagine the opportunities for confusion if username 1000 has UID 253? Or, in general, for numeric usernames that do not match the UID? Simlarly with groups, of course. – Jonathan Leffler 13 hours ago
    
I have an LDAP system where some users have their (numeric) employee code/registration number as the username. I quickly learned to canonicalize to user IDs (chown -R $(id -u $username) ...). – muru 8 hours ago

here is a test on ubuntu 14.04 using numbers:

root@ubuntu:~# useradd 232
root@ubuntu:~# mkdir /home/232
root@ubuntu:~# chown 232.232 /home/232
root@ubuntu:~# passwd 232
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@ubuntu:~# login
c2 login: 232
Password: 
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

 System information disabled due to load higher than 2.0

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.


$ 
$ whoami
232

and one using unicode U+1F600 - πŸ˜€

root@c2:~# useradd πŸ˜€
root@c2:~# mkdir /home/πŸ˜€
root@c2:~# chown πŸ˜€.πŸ˜€ /home/πŸ˜€
root@c2:~# passwd πŸ˜€
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@c2:~# login
c2 login: πŸ˜€
Password: 
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

 System information disabled due to load higher than 2.0

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

$ whoami
πŸ˜€

This is probably the worst idea I had:

root@c2:~# useradd '&#%^()!@~*?<>=|'
root@c2:~# passwd '&#%^()!@~*?<>=|'
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@c2:~# mkdir '/home/&#%^()!@~*?<>=|'
root@c2:~# chown '&#%^()!@~*?<>=|.&#%^()!@~*?<>=|' '/home/&#%^()!@~*?<>=|'
root@c2:~# login
c2 login: &#%^()!@~*?<>=|     
Password: 
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-generic x86_64)
**** text removed ****
applicable law.

$ whoami
&#%^()!@~*?<>=|

Clearly you can add such a user, although I'm not sure this is a good idea in the long run.

share|improve this answer
8  
wow ubuntu permits that? I wonder what happens if you try to useradd 1000 (assuming you already have a user with UID 1000) – thomas_d_j yesterday
3  
+1 for only all of the forbidden symbols! – ΞˆΟΞΉΞΊ ΞšΟ‰Ξ½ΟƒΟ„Ξ±Ξ½Ο„ΟŒΟ€ΞΏΟ…Ξ»ΞΏΟ‚ yesterday
2  
Oh, I can think of worse... – OrangeDog yesterday
1  
@LiamDawson: cd '/home/*/' would work just fine. So would cd "$HOME". The might be a few broken scripts that assume glob-expanding $HOME doesn't change it, but those would be bugs. – Peter Cordes yesterday
2  
@IsmaelMiguel: A literal \0 in /etc/passwd would probably break a lot of programs that parse it. But you probably couldn't get add a user with that name in the first place, using standard tools. System calls like mkdir(2) also use 0-terminated implicit-length strings, so you can't create /home/\0/, because that path is just /home. – Peter Cordes 17 hours ago

A *Nix username is generally a 32 character long string created by the utility useradd. This is, as you said, a direct result of early Unix (BSD technically) standards. According to the FreeBSD Man Page passwd(5):

The login name must not begin with a hyphen (`-'), and cannot contain 8-bit characters, tabs or spaces, or any of these symbols: `,:+&#%^()!@~*?<>=|/"'. The dollar symbol (`$') is allowed only as the last character for use with Samba. No field may contain a colon (`:') as this has been used historically to separate the fields in the user data- base.

Certain *Nix systems used to throw obscure errors when presented with special characters in usernames, so eventually, the special characters were banned. In most modern *Nix systems it would be relatively easy to change the passwd/useradd utilities to support special character usernames, but most people are hesitant to change such an unimportant thing, as it would have little effect and would cause backwards incompatibility.

EDIT:
As Adonis said, it is in fact possible to do this in a modern Linux distribution, however it is ill-advised (especially when encountering standardized or legacy programs).

share|improve this answer
5  
Sure but the question doesn't even mention special characters. It asks why user names can't start with digits (which aren't special characters). – don_crissti yesterday
    
Sure @don_crissti, would you prefer me to re-ask why historically a username can't start with a space, then ask seperately why it historially an't start with each of the symbols, then ask &c historically end with a $ ? This "answer" doesn't fit as a comment, which it clearly is, yet contains useful information related to the question. – frumbert 4 hours ago

Your Answer

 
discard

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.