Linux/Unix username length limit

8,052

Don't try making the login name longer, you'll probably find loads of places it breaks.

Note that you don't have a problem with the number of possible login names (you only get UID_MAX-UID_MIN uids anyway, which is 59,000 on my system).

The problem is just with how descriptive they are, but fortunately there's another field intended to be descriptive: the GECOS/comment field. Just put the URL in there, and make the username either a 32-character hash of that, or simply the UID in base 10.

Then, best case you can always hash the URL to get UID, and worst case you need a reverse lookup from URL to UID, which is pretty trivial for 59,000 items - even a grep of /etc/passwd would be sufficient.

Share:
8,052

Related videos on Youtube

PSkocik
Author by

PSkocik

Updated on September 18, 2022

Comments

  • PSkocik
    PSkocik over 1 year

    Would it be difficult to increase the limit or would it just be a one-place change?

    I have a system that could really elegantly make use of the Unix multiuser model for process isolation but I'd need much longer usernames than just 32 characters.

    Is the name length standardized (POSIX)?

    • Jonathan Roberts
      Jonathan Roberts almost 9 years
      Can't you map the longer names onto 32 characters?
    • PSkocik
      PSkocik almost 9 years
      Short answer: No; Long answer: The system I speak of is a nonconflicting package manager with packages of potentially really long url-based fully qualified names (which in certain contexts abbreviate for user convenience). I'd like to add the option of optionally jailing packages to their own, dynamically-created (at installation time) system user, but in order to preserve the nonconflicting nature of the system, the names of dynamically created users would need to be based on the fully qualified name of the appropriate package. Mapping to a shorter wouldn't be guaranteedly conflictless.
    • Drav Sloan
      Drav Sloan almost 9 years
      Sounds like the use of a database to map your really-long-lots-of-info-in-ther-username names to a simple name is a better solution. (this would be a much shorter job than trying to fix all the places to to support longer usernames).
    • Fabby
      Fabby almost 9 years
      Not even when using the full UNICODE character set? Using 7-bit ASCII (-32 control characters) gives you only (127-32)*32=3040 possibilities, but using full UNICODE gives you 2096096 possibilities for a double-byte name...
    • Useless
      Useless almost 9 years
      Surely that's (127-32)^32, not (127-32)*32?
    • dr_
      dr_ almost 9 years
      What about using the GECOS field to store additional information that doesn't fit in the 32-char limited username?
    • Арсений Черенков
      Арсений Черенков almost 9 years
      a one-way mapping from arbitrary long string to 32 chat can be achieved using md5. (there is however no guarantee that you get a name conflict).
  • PSkocik
    PSkocik almost 9 years
    Do you know if there are any limits on the length of the comment field (character set restrictions don't worry me as I only need a very basic character set ([a-zA-Z_0-9])?
  • Useless
    Useless almost 9 years
    Not on Linux at least (you can see that glibc:fgetpwent grows its buffer as required). The GECOS field is an addition to the POSIX standard, so you'd need to check any other platforms individually.