42

I'd like to know what the maximum username length is for current GNU/Linux systems, e.g. Ubuntu 11.04.

8 characters appears to be some historical standard, but I've already noticed on my current Ubuntu system that this limit does not apply.

user9517
  • 114,104
  • 20
  • 206
  • 289
Klaas van Schelven
  • 559
  • 1
  • 4
  • 6

4 Answers4

44

The current limit is 32 characters (according to useradd man page).

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
20

The answer varies somewhat.

useradd(1) references a limit of 32 characters. This is based AFAIU on libc6.

Some utilities or systems may impose shorter names or behave inconsistently when presented with longer names, including top, ps, w/who, finger, NFS, and various multi-platform directory systems (NIS/NIS+, SMB, CIFS, Kerberos), potentially based on limitations of other/remote platforms. Many of the various psutil commands will display a UID rather than username if the latter exceeds 8 characters.

Some utilities and applications may impose their own arbitrary limitations. E.g.: IBM's DB2 apparently won't allow logins from users with usernames exceeding 8 characters: https://www.toolbox.com/tech/data-management/question/length-of-username-permitted-on-db2-95-aix-6-012010/

8 characters is a generally sane limit, and saves typing.

Sandburg
  • 125
  • 5
  • 3
    Thank you for this answer. Just one note: If you use linux users for isolated computing environments, 8 characters is often too small. At least if you want the names to be readable. – guettli Mar 20 '14 at 12:19
2

As other answers have explained, longer usernames are possible, but another practical reason to try to limit to 8 chars maximum is that ps(1) reports numeric uids instead of usernames beyond 8 chars.

Simon Pickup
  • 141
  • 5
  • Recent versions of ps are now reporting the first seven characters of a >8 character account suffixed with an asterisk, E.g. "dockerr*" for dockerroot. – Stephen P. Schaefer Aug 07 '20 at 13:52
1

The answer, from the kernel's perspective, is dependent on glibc and what LOGIN_NAME_MAX is -it is closer to 256 these days.

From /usr/include/bits/local_lim.h on centos 7:

/* Maximum login name length.  This is arbitrary.  */
#define LOGIN_NAME_MAX      256

However, that is a different limit then if you use adduser/addgroup or useradd/groupadd, because those depend on the files underneath.

Recall that glibc can be configured to use a different backend via /etc/nsswitch.conf, e.g.

passwd:     files sss

In this case, it would rely on /etc/passwd first, which may (sort of, by way of useradd/groupadd) have a 32 character limit on the user/group name, then fall back to sss (sssd), which is likely to have a much different limit (1024 it seems if backed by ActiveDirectory).

Note that /usr/include/grp.h effectively defines 256 as well for group names (checked on centos 7).

So, for local accounts, the limit is likely to be what is referenced in useradd/groupadd (likely to be ~31). For different nss implementations, it will likely depend on the server restrictions and glibc on the system - in many cases this is likely to be 256.

Brian
  • 111
  • 1