Useradd

如何批量添加禁用密碼的使用者?

  • October 27, 2020

正在做:

# newusers
username::1002:1002::/home/username:/bin/bash
^D
No password supplied
No password supplied
No password supplied
newusers: (user username) pam_chauthtok() failed, error:
Authentication token manipulation error
newusers: (line 1, user username) password not changed

添加沒有密碼的使用者(在 中使用雜湊“!” /etc/shadow)。

正在做:

# newusers
username:*:1002:1002::/home/username:/bin/bash
^D

添加密碼為“*”的使用者(在 中帶有一些雜湊/etc/shadow)。

但是,我需要的是在/etc/shadow.

我怎麼做?

將密碼欄位留空。 newusers將反复抱怨“未提供密碼”並且無法更改密碼,但使用者將!在影子密碼欄位中創建(即無效密碼)。

username::1002:1002::/home/username:/bin/bash

代替:

username:*:1002:1002::/home/username:/bin/bash

例如:

# echo "username::10000:10000::/home/username:/bin/bash" | newusers 
No password supplied
No password supplied
No password supplied
newusers: (user username) pam_chauthtok() failed, error:
Authentication token manipulation error
newusers: (line 1, user username) password not changed

# tail -1 /etc/passwd
username:x:10000:10000::/home/username:/bin/bash

# tail -1 /etc/shadow
username:!:16713:0:99999:7:::

引用自:https://unix.stackexchange.com/questions/233940