我想使用该adduser命令通过 shell 脚本添加用户(密码已禁用)。
默认情况下,adduser会提示您输入各种值(例如,全名)。有没有办法通过命令行提交这些值?还是我需要useradd代替?
Zok*_*oke 349
使用--gecos选项跳过chfn交互部分。
adduser --disabled-password --gecos "" username
Run Code Online (Sandbox Code Playgroud)
这一切都在手册页中。不是最明显的公式。
--gecos GECOS
Set the gecos field for the new entry generated. adduser will
not ask for finger information if this option is given.
Run Code Online (Sandbox Code Playgroud)
GECOS 字段是一个逗号分隔的列表,例如:Full name,Room number,Work phone,Home phone,尽管手册页提到了finger information 详细信息 - 维基百科
希望这对你有帮助。
Tho*_*ner 60
useradd can also add users and does not appear to have any form of prompting built in.
useradd -m -p <encryptedPassword> -s /bin/bash <user>
Run Code Online (Sandbox Code Playgroud)
-m, --create-home: Create user home directory-p, --password: Specify user password; skip to have it disabled-s, --shell: Default shell for logon user
Blank will use default login shell specified by the SHELL variable in /etc/default/useradd
<user> with the login name<encryptedPassword> with the encrypted passwordThere are a lot of crypt3 implementations that can generate a hashed password. The whole thing is your hashed password.
结果输出格式:散列机制($6对于 sha-512),随机盐(第二个美元符号后的八个字节$ASDF1234),余数是有效载荷。
密码 mkpasswd -m sha-512
(mkpasswd由whois包提供)
结果输出格式:前 2 个字节是您的盐,其余是有效负载。整件事就是你的散列密码。
mkpasswd由whois包提供)openssl passwd -cryptperl -e "print crypt('password');"python3 -c 'import crypt; print(crypt.crypt("password"))'你可以像这样结合@ThorSummoner @Zoke 所说的:
username=jovyan
password=jovyan
adduser --gecos "" --disabled-password $username
chpasswd <<<"$username:$password"
Run Code Online (Sandbox Code Playgroud)
我正在为我的 Jupyter docker-stack 做这个。它允许在 Dockerfile 中进行完整的无头设置。
| 归档时间: |
|
| 查看次数: |
147132 次 |
| 最近记录: |