Home ยป Why can’t Linux usernames begin with numbers?

Why can’t Linux usernames begin with numbers?

Solutons:


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:
`,:+&#%^()!@~*?<>=”https://unix.stackexchange.com/”‘. 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).

Related Solutions

Joining bash arguments into single string with spaces

[*] I believe that this does what you want. It will put all the arguments in one string, separated by spaces, with single quotes around all: str="'$*'" $* produces all the scripts arguments separated by the first character of $IFS which, by default, is a space....

AddTransient, AddScoped and AddSingleton Services Differences

TL;DR Transient objects are always different; a new instance is provided to every controller and every service. Scoped objects are the same within a request, but different across different requests. Singleton objects are the same for every object and every...

How to download package not install it with apt-get command?

Use --download-only: sudo apt-get install --download-only pppoe This will download pppoe and any dependencies you need, and place them in /var/cache/apt/archives. That way a subsequent apt-get install pppoe will be able to complete without any extra downloads....

What defines the maximum size for a command single argument?

Answers Definitely not a bug. The parameter which defines the maximum size for one argument is MAX_ARG_STRLEN. There is no documentation for this parameter other than the comments in binfmts.h: /* * These are the maximum length and maximum number of strings...

Bulk rename, change prefix

I'd say the simplest it to just use the rename command which is common on many Linux distributions. There are two common versions of this command so check its man page to find which one you have: ## rename from Perl (common in Debian systems -- Ubuntu, Mint,...

Output from ls has newlines but displays on a single line. Why?

When you pipe the output, ls acts differently. This fact is hidden away in the info documentation: If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is...

mv: Move file only if destination does not exist

mv -vn file1 file2. This command will do what you want. You can skip -v if you want. -v makes it verbose - mv will tell you that it moved file if it moves it(useful, since there is possibility that file will not be moved) -n moves only if file2 does not exist....

Is it possible to store and query JSON in SQLite?

SQLite 3.9 introduced a new extension (JSON1) that allows you to easily work with JSON data . Also, it introduced support for indexes on expressions, which (in my understanding) should allow you to define indexes on your JSON data as well. PostgreSQL has some...

Combining tail && journalctl

You could use: journalctl -u service-name -f -f, --follow Show only the most recent journal entries, and continuously print new entries as they are appended to the journal. Here I've added "service-name" to distinguish this answer from others; you substitute...

how can shellshock be exploited over SSH?

One example where this can be exploited is on servers with an authorized_keys forced command. When adding an entry to ~/.ssh/authorized_keys, you can prefix the line with command="foo" to force foo to be run any time that ssh public key is used. With this...

Why doesn’t the tilde (~) expand inside double quotes?

The reason, because inside double quotes, tilde ~ has no special meaning, it's treated as literal. POSIX defines Double-Quotes as: Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the...

What is GNU Info for?

GNU Info was designed to offer documentation that was comprehensive, hyperlinked, and possible to output to multiple formats. Man pages were available, and they were great at providing printed output. However, they were designed such that each man page had a...

Set systemd service to execute after fstab mount

a CIFS network location is mounted via /etc/fstab to /mnt/ on boot-up. No, it is not. Get this right, and the rest falls into place naturally. The mount is handled by a (generated) systemd mount unit that will be named something like mnt-wibble.mount. You can...

Merge two video clips into one, placing them next to each other

To be honest, using the accepted answer resulted in a lot of dropped frames for me. However, using the hstack filter_complex produced perfectly fluid output: ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4 ffmpeg -i input1.mp4 -i input2.mp4...

How portable are /dev/stdin, /dev/stdout and /dev/stderr?

It's been available on Linux back into its prehistory. It is not POSIX, although many actual shells (including AT&T ksh and bash) will simulate it if it's not present in the OS; note that this simulation only works at the shell level (i.e. redirection or...

How can I increase the number of inodes in an ext4 filesystem?

It seems that you have a lot more files than normal expectation. I don't know whether there is a solution to change the inode table size dynamically. I'm afraid that you need to back-up your data, and create new filesystem, and restore your data. To create new...

Why doesn’t cp have a progress bar like wget?

The tradition in unix tools is to display messages only if something goes wrong. I think this is both for design and practical reasons. The design is intended to make it obvious when something goes wrong: you get an error message, and it's not drowned in...