43T*_*cts 83 linux users history
有技术原因吗?这是否是 Linux 或 Unix 早期的产物,如果是,是否有它持续存在的原因?
tho*_*d_j 138
某些命令(例如chown)可以接受用户名或数字用户 ID,因此允许全数字用户名会破坏这一点。
允许名称以数字开头并包含一些字母的规则可能被认为不值得付出努力;相反,只需要以字母字符开头。
编辑:
从其他回应看来,一些发行版已经颠覆了这一限制;在这种情况下,根据GNU Core Utils 文档:
POSIX 要求这些命令首先尝试将指定的字符串解析为名称,并且只有一次失败,然后尝试将其解释为 ID。
$ useradd 1000 # on most systems this will fail with:
# useradd: invalid user name '1000'
$ mkdir /home/1000
$ chown -R 1000 /home/1000 # This will first try to map
# to username "1000", but this may easily be misinterpreted.
Run Code Online (Sandbox Code Playgroud)
添加名为“0”的用户只会自找麻烦(UID 0 == root 用户)。但是,请注意,组/用户 ID 参数可以以“+”开头,以强制将其解释为整数。
ado*_*nis 82
这是使用数字对 ubuntu 14.04 进行的测试:
root@ubuntu:~# useradd 232
root@ubuntu:~# mkdir /home/232
root@ubuntu:~# chown 232.232 /home/232
root@ubuntu:~# passwd 232
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ubuntu:~# login
c2 login: 232
Password:
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information disabled due to load higher than 2.0
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
$
$ whoami
232
Run Code Online (Sandbox Code Playgroud)
一个使用 unicode U+1F600 -
root@c2:~# useradd
root@c2:~# mkdir /home/
root@c2:~# chown . /home/
root@c2:~# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@c2:~# login
c2 login:
Password:
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information disabled due to load higher than 2.0
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
0 packages can be updated.
0 updates are security updates.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
$ whoami
Run Code Online (Sandbox Code Playgroud)
这可能是我最糟糕的想法:
root@c2:~# useradd '&#%^()!@~*?<>=|'
root@c2:~# passwd '&#%^()!@~*?<>=|'
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@c2:~# mkdir '/home/&#%^()!@~*?<>=|'
root@c2:~# chown '&#%^()!@~*?<>=|.&#%^()!@~*?<>=|' '/home/&#%^()!@~*?<>=|'
root@c2:~# login
c2 login: &#%^()!@~*?<>=|
Password:
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-generic x86_64)
**** text removed ****
applicable law.
$ whoami
&#%^()!@~*?<>=|
Run Code Online (Sandbox Code Playgroud)
很明显,您可以添加这样的用户,但我不确定从长远来看这是一个好主意。
*Nix 用户名通常是由实用程序创建的 32 个字符长的字符串useradd。正如您所说,这是早期 Unix(技术上为 BSD)标准的直接结果。根据 FreeBSD 手册页passwd(5):
登录名不得以连字符 (`-') 开头,并且不能包含 8 位字符、制表符或空格或以下任何符号:`,:+&#%^()!@~*?<> =|/"'。美元符号 (`$') 仅允许作为用于 Samba 的最后一个字符。任何字段都不能包含冒号 (`:'),因为这在历史上已用于分隔用户中的字段数据库。
某些 *Nix 系统过去常常在用户名中出现特殊字符时抛出模糊错误,因此最终,特殊字符被禁止。在大多数现代 *Nix 系统中,更改passwd/useradd实用程序以支持特殊字符用户名相对容易,但大多数人不愿更改这样一个不重要的东西,因为它几乎没有影响并且会导致向后不兼容。
编辑:
正如阿多尼斯所说,实际上可以在现代 Linux 发行版中做到这一点,但这是不明智的(尤其是在遇到标准化或遗留程序时)。