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
Valid special characters allowed in a CentOS 7 username?
Valid special characters allowed in a CentOS 7 username?
Last edited by bodisha on 2019/03/20 16:37:11, edited 2 times in total.
-
- Posts: 519
- Joined: 2012/06/26 14:20:47
Re: Valid User name characters allowed in CentOS 7?
It's under CAVEATS in the useradd man page.
Re: Valid special characters allowed in a CentOS 7 username?
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.
Re: Valid special characters allowed in a CentOS 7 username?
I suggest you just stick to what POSIX says, even if there is no check in C7's useradd.
Re: Valid special characters allowed in a CentOS 7 username?
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
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
-
- Posts: 519
- Joined: 2012/06/26 14:20:47
Re: Valid special characters allowed in a CentOS 7 username?
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.
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.
Re: Valid special characters allowed in a CentOS 7 username?
On a fully patched C7 machine man 5 passwd contains the field description:
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!
I do note that the revision date for the man page is 2012-05-03!name This is the user's login name. It should not contain capital letters.
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!