我想使用该adduser命令通过Shell脚本添加用户(具有禁用的密码)。
默认情况下,adduser提示您输入各种值(例如,全名)。有什么办法可以通过命令行提交这些值?还是我需要useradd代替?
我想使用该adduser命令通过Shell脚本添加用户(具有禁用的密码)。
默认情况下,adduser提示您输入各种值(例如,全名)。有什么办法可以通过命令行提交这些值?还是我需要useradd代替?
Answers:
使用该--gecos选项可跳过chfn交互部分。
adduser --disabled-password --gecos "" username
全部在手册页中。不是最明显的表述。
--gecos GECOS
Set the gecos field for the new entry generated. adduser will
not ask for finger information if this option is given.
GECOS字段是一个用逗号分隔的列表,例如:Full name,Room number,Work phone,Home phone,尽管该手册页提到了finger information 详细信息-Wikipedia
希望这对您有帮助。
useradd 也可以添加用户,并且似乎没有内置任何形式的提示。
useradd -m -p <encryptedPassword> -s /bin/bash <user>
-m,--create-home:创建用户主目录-p,--password:指定用户密码;跳过以禁用它-s,--shell:登录用户的默认外壳
空白将使用由中的SHELL变量指定的默认登录外壳/etc/default/useradd
<user>用登录名代替<encryptedPassword>用加密的密码代替有许多可以生成哈希密码的crypt3实现。整个过程就是您的哈希密码。
结果输出格式:哈希机制($6对于sha-512),随机盐(第二个美元符号后的八个字节$ASDF1234),其余部分为有效负载。
mkpasswd mkpasswd -m sha-512
(mkpasswd由whois包装提供)
结果输出格式:前2个字节是您的盐,其余部分是有效负载。整个过程就是您的哈希密码。
mkpasswd由whois软件包提供)openssl passwd -cryptperl -e "print crypt('password');"python3 -c 'import crypt; print(crypt.crypt("password"))'adduser与截然不同useradd,我知道。
-v或-vv或-vvv,以查看出了什么问题并在SO或Google上搜索错误消息。
sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config和sudo service ssh restart
adduser在我的(最新)Ubuntu版本中不存在。