Why limit maximum username length to 8 characters?

It's a limitation of legacy Unix systems, and the NIS directory service in particular. Usually, this restriction is just in place if the organization is trying to keep usernames consistent across all applications (which is generally a good idea).


The main one I’ve seen problems with recently has been ps on Solaris (10), it lops the 9th+ characters off, so for example if you needed to grep for the username it wouldn’t match.

$ sudo -u longusername ps -fu longusername
     UID   PID  PPID   C    STIME TTY         TIME CMD
longuser 14012 11985   0 09:58:39 pts/2       0:00 ps -fu longusername

If you do an ls -l on a directory with files belonging to that user, the columns get pushed out of alignment.

$ ls -ld /export/home/l*
drwxr-xr-x   2 lauser   users        6 Mar 23 10:21 /export/home/lzuser
drwxr-xr-x   2 longusername users        6 May  4 10:02 /export/home/longusername
drwxr-xr-x   2 lzuser   users        6 Mar 12 11:21 /export/home/lzuser

Basically you would need to be wary of any tool that dealt with login names and not just UIDs. That could include things that read from or wrote to log files or databases, or used the output of tools like last, who, finger, ls, ps etc.

A quick Google turned up this page:

http://fixunix.com/sun/113647-username-lenght-more-then-8-characters.html

Which adds some more reasons.

With regards best practices for username creation, there can also be complications from using logins in capitals instead of lower case, so that should be avoided too.

When some (older) systems, when see a login in only capitals, they helpfully default to assuming that the user's terminal doesn't support lower case, so set EVERYTHING to be in capitals (which can prevent entering the password and being able to type Unix commands once you login!)

Edit (16/04/2019):

I've just noticed on RHEL 7.5, that the output of ps doesn't play nicely either:

$ ps -fulongusername
UID        PID  PPID  C STIME TTY          TIME CMD
longuse+  1230 27243  0 Apr13 pts/0    00:00:00 vim somescript.sh
longuse+  1701 27243  0 Apr05 pts/0    00:00:00 vim another-script.sh
longuse+  3116 27243  0 Apr12 pts/0    00:00:01 vim test_script.sh

It truncates the username with a '+', which isn't helpful if you're not familiar with which user it will be and means you can't rely on the output of ps e.g. as input to a script that needs to know who owns a process.