Why can't Linux usernames begin with numbers?
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; in this case, according to the GNU Core Utils documentation:
POSIX requires that these commands first attempt to resolve the specified string as a name, and only once that fails, then try to interpret it as an ID.
$ useradd 1000 # on most systems this will fail with:
# useradd: invalid user name '1000'
$ mkdir /home/1000
$ chown -R 1000 /home/1000 # This will first try to map
# to username "1000", but this may easily be misinterpreted.
Adding a user named '0' would just be asking for trouble (UID 0 == root user). However, note that group/user ID arguments can be preceded by a '+' to force their interpretation as an integer.
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.
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).