博客园  :: 首页  :: 管理

对于公司的Linux服务器,创建个人用户时,都是要求使用个人的编号来创建,此前一直没有遇到问题

直到今天遇到一个员工编号是纯数字的,在使用user add xxxx 创建时报:useradd: invalid user name '5201351', 如下:

其实想了一下,有这样的限制也是有道理的,linux系统用户的uid就是纯数字

比如像id 之类的命令,是可以直接指定uid或者用户名的,如果是纯数字了,到底应该视为什么呢?

不过笔者测试过,冲突了还是只显示用户名为纯数字的用户信息,总之只会显示一个用户的信息

笔者去查询了redhat相关的文档,其中redhat 7.6 版本的Release_Notes已经说明了,如下:

All-numeric user and group names in shadow-utils are now deprecated
Creating user and group names consisting purely of numeric characters using the useradd and
groupadd commands is now deprecated and will be removed from the system with the next major
release. Such names can potentially confuse many tools that work with user and group names and user
and group ids (which are numbers).

也就是说,从7.6版本开始弃用创建纯数字的用户名,当然其实还是有可能临时解决的方法,如下文会提到

但是从8版本会直接删除那种使用命令创建纯数字用户名的方式(笔者在8.1的版本中,测试过,通过改变特殊变量也不能实现了)

后笔者在Red Hat Bugzilla – Bug 1672958 文档中也发现了此解释,如下

The useradd and groupadd commands disallow user and group names
consisting purely of numeric characters since Red Hat Enterprise Linux 7.6.
The reason for not allowing such names is that this can confuse potentially
many tools that work with user and group names and user and group ids
(which are numbers). However due to some deployments depending on allowing all-numeric user names
this erratum makes useradd and groupadd commands to allow all-numeric user and group names
if environment variable SHADOW_ALLOW_ALL_NUMERIC_USER is set.
Please note that the all-numeric user and group names are
deprecated in Red Hat Enterprise Linux 7 and the support will be completely removed in Red Hat Enterprise Linux 8.

 

 

+++解决方法>>>>>(适用于7.6~7.9版本):

1、但是终究还是有方法改变这个限制的,可以使用export定义SHADOW_ALLOW_ALL_NUMERIC_USER变量的值为1,如下:

export SHADOW_ALLOW_ALL_NUMERIC_USER=1
useradd 123456
useradd -u 1351 -g 2099 -G wheel,ssh-users -c "qq_5201351"  5201351

另说明:只需要在创建用户时执行上面第一条命令的即可,临时生效,所以下次登录,会发现不会影响系统的默认策略的

  

 

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/14848730.html