Valid special characters allowed in a CentOS 7 username?

General support questions
Post Reply
bodisha
Posts: 54
Joined: 2015/06/06 23:55:29

Valid special characters allowed in a CentOS 7 username?

Post by bodisha » 2019/03/20 15:18:45

Fast and dirty... Trying to figure out how CentOS 7 identifies what is considered a valid character in a naming convention when a user account is created.

Was playing around with useradd to confirm my understanding of what CentOS considered valid characters in a user name and to my surprise the useradd command accepted '_' and '.'... Which got me wondering where valid/invalid characters are established in CentOS

The useradd man page doesn't mention valid characters... And google searches said this is done with NAME_REGEX (For ubuntu at least)... and had me looking for it in a adduser.conf file... which does not exist in CentOS 7... And I haven't been able to locate a CentOS/Red Hat specific source on google about this... But I've also looked in /etc/login.defs and /etc/default/useradd with no luck

Can anyone direct me to the mechanism in CentOS does this? This started off more out of curiosity... but my OCD kicked in about this and it's driving me nuts!

Thanks
Last edited by bodisha on 2019/03/20 16:37:11, edited 2 times in total.

stevemowbray
Posts: 519
Joined: 2012/06/26 14:20:47

Re: Valid User name characters allowed in CentOS 7?

Post by stevemowbray » 2019/03/20 16:25:13

It's under CAVEATS in the useradd man page.

bodisha
Posts: 54
Joined: 2015/06/06 23:55:29

Re: Valid special characters allowed in a CentOS 7 username?

Post by bodisha » 2019/03/20 16:35:09

Nope... Already read the man page and it doesn't' say anything about valid characters in it... All it says under caveats is:
You may not add a user to a NIS or LDAP group. This must be performed on the corresponding server.

Similarly, if the username already exists in an external user database such as NIS or LDAP, useradd will deny the user account creation request.

Usernames may only be up to 32 characters long.

chemal
Posts: 776
Joined: 2013/12/08 19:44:49

Re: Valid special characters allowed in a CentOS 7 username?

Post by chemal » 2019/03/20 17:13:33

I suggest you just stick to what POSIX says, even if there is no check in C7's useradd.

User avatar
TrevorH
Site Admin
Posts: 33215
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Valid special characters allowed in a CentOS 7 username?

Post by TrevorH » 2019/03/20 17:50:51

Interestingly on Debian, man useradd does contain info in the caveats section:
It is usually recommended to only use usernames that begin with a lower case letter or an underscore,
followed by lower case letters, digits, underscores, or dashes. They can end with a dollar sign. In
regular expression terms: [a-z_][a-z0-9_-]*[$]?

On Debian, the only constraints are that usernames must neither start with a dash ('-') nor plus ('+')
nor tilde ('~') nor contain a colon (':'), a comma (','), or a whitespace (space: ' ', end of line: '\n',
tabulation: '\t', etc.). Note that using a slash ('/') may break the default algorithm for the definition
of the user's home directory.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

stevemowbray
Posts: 519
Joined: 2012/06/26 14:20:47

Re: Valid special characters allowed in a CentOS 7 username?

Post by stevemowbray » 2019/03/21 10:30:16

This is in my useradd man page on CentOS 7:
CAVEATS
You may not add a user to a NIS or LDAP group. This must be performed on the corresponding server.

Similarly, if the username already exists in an external user database such as NIS or LDAP, useradd will deny the user
account creation request.

Usernames may contain only lower and upper case letters, digits, underscores, or dashes. They can end with a dollar sign.
Dashes are not allowed at the beginning of the username. Fully numeric usernames and usernames . or .. are also disallowed.
It is not recommended to use usernames beginning with . character as their home directories will be hidden in the ls
output. In regular expression terms: [a-zA-Z0-9_.][a-zA-Z0-9_.-]*[$]?

Usernames may only be up to 32 characters long.

EDIT: just noticed this is missing on a machine which has not yet been updated to the latest shadow-utils package.

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: Valid special characters allowed in a CentOS 7 username?

Post by MartinR » 2019/03/21 11:33:06

On a fully patched C7 machine man 5 passwd contains the field description:
name This is the user's login name. It should not contain capital letters.
I do note that the revision date for the man page is 2012-05-03!

When UNIX was still fairly new and people used character terminals, using an uppercase username indicated to the OS that your terminal could only handle uppercase. I hit this issue trying to use the same username in VMS and Digital Unix which turned off recognition of lowercase. You can image the effect that had on commands and the filesystem!

Post Reply