對於公司的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