kir*_*iri 43
POSIX指出这一下用户名:
[...] 为了在符合 IEEE Std 1003.1-2001 的系统之间可移植,该值由可移植文件名字符集中的字符组成。连字符不应用作可移植用户名的第一个字符。
...其中可移植文件名字符集是:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 . _ -
Run Code Online (Sandbox Code Playgroud)
此外,该文件的联机帮助页/etc/adduser.conf
状态:
VALID NAMES
adduser and addgroup enforce conformity to IEEE Std 1003.1-2001,
which allows only the following characters to appear in group
and user names: letters, digits, underscores, periods, at signs
(@) and dashes. The name may not start with a dash. The "$" sign
is allowed at the end of usernames (to conform to samba).
An additional check can be adjusted via the configuration
parameter NAME_REGEX to enforce a local policy.
Run Code Online (Sandbox Code Playgroud)
虽然这两个规范似乎都包含点,但 Ubuntu(至少在我的 13.04 上)似乎不允许它:
? sudo adduser as.df
adduser: Please enter a username matching the regular expression configured
via the NAME_REGEX[_SYSTEM] configuration variable. Use the `--force-badname'
option to relax this check or reconfigure NAME_REGEX.
Run Code Online (Sandbox Code Playgroud)
NAME_REGEX
Ubuntu 中的默认值是(来自/etc/adduser.conf
联机帮助页):
^[a-z][-a-z0-9]*$
Run Code Online (Sandbox Code Playgroud)
_
,@
或.
。总之,一个点.
可以用于 Ubuntu 用户名,NAME_REGEX
只需在/etc/adduser.conf
. 既然它符合 POSIX,那么.
在任何符合 POSIX 的程序中使用用户名应该没有任何问题。
在终端中运行此命令:
sudo nano /etc/adduser.conf
Run Code Online (Sandbox Code Playgroud)找到这一行(靠近文件末尾)
#NAME_REGEX="^[a-z][-a-z0-9]*$"
Run Code Online (Sandbox Code Playgroud)
并将其替换为
NAME_REGEX='^[a-z][-.a-z0-9]*$'
Run Code Online (Sandbox Code Playgroud)
请注意,-
必须保留在括号表达式中的第一个字符[...]
,否则将其视为指定范围a-z
。
按Ctrl+ X,然后Y,然后Enter。
参考:
小智 6
Marc Haber 解释了 Debian bug #604242中可能存在的缺点(默认情况下允许用户名中包含点):
用户名中包含点会导致使用 scipt 产生一些问题
chown
,该 scipt 仍然接受点作为用户名和组名之间的分隔符。如果chown
仍然接受点,则会有使用此表示法的脚本,如果用户名包含点,则会中断。我建议保留当前默认值(可以通过本地配置覆盖),直到
chown
停止接受点作为分隔符。
并且chown
仍然接受点作为分隔符,尽管它不再被记录。我同意 POSIX 兼容性应该占上风,而且我确实在多个系统上使用了包含点的用户名,没有任何不利影响。