一个学生刚刚问到,用户名中有一个点(
.
)会有什么不利影响。例如:john.doe
这会对系统或任何应用程序产生什么影响?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 . _ -
/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.
⊳ 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.
NAME_REGEX
是(来自/etc/adduser.conf
手册页):^[a-z][-a-z0-9]*$
sudo nano /etc/adduser.conf
#NAME_REGEX="^[a-z][-a-z0-9]*$"
将其替换为
NAME_REGEX='^[a-z][-.a-z0-9]*$'
请注意,-
必须保持方括号表达式 [...]
中的第一个字符,否则它将被视为指定范围 a-z
。
在用户名中使用点号会导致一些问题,因为仍然接受点号作为用户名称和组名称之间的分隔符,因此使用
chown
的脚本会出现问题。如果chown
仍然接受点号,则将使用此记号的脚本会断开,如果用户名包含点,则会出现问题。我建议保留当前默认设置(可以通过本地配置覆盖),直到
chown
停止接受点号作为分隔符为止。
chown
仍然接受点作为分隔符,尽管它不再被记录在文档中。我同意POSIX兼容性应该优先考虑,在几个系统上确实使用了包含点的用户名而没有任何负面影响。
NAME_REGEX="^[a-z][-a-z0-9_\.]*\$"
无法完成任务,尽管我希望它能够工作。它会产生你在 然而 段落中提到的相同错误。 - 0xC0000022Lfoo.bar
这样的东西吗?我不明白为什么.
不能像通常在 Perl 中可以转义一样进行转义(adduser
是一个 Perl 脚本)。 - 0xC0000022L/etc/adduser.conf
中添加NAME_REGEX="^[a-z][-a-z0-9_.]*\$?$"
起了作用。 - Mariouseradd
函数:sudo useradd -m my.user
。这就是我们在Userify中所做的,而且它也适用于多个平台。 - fatal_erroruseradd
默认不会设置用户的 shell,最好使用sudo adduser --force-badname my.user
。 - gmk57