以非交互方式运行adduser

我想使用adduser命令通过shell脚本添加用户(具有禁用的密码)。

默认情况下, adduser会提示您输入各种值(例如,全名)。 有没有办法通过命令行提交这些值? 或者我需要使用useradd吗?

使用--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 详细信息 – 维基百科

希望这对你有所帮助。

useradd也可以添加用户,并且似乎没有内置任何forms的提示。

 useradd -m -p  -s /bin/bash  
  • -m--create-home create --create-home :创建用户主目录
  • -p , – password:指定用户密码; 跳过将其禁用
  • -s , – --shell :登录用户的默认shell

    Blank将使用/etc/default/useradd SHELL变量指定的默认登录shell

  • 用登录名替换
  • 加密密码替换

生成哈希密码:

有很多 crypt3实现可以生成哈希密码。 整件事是你的哈希密码。

Sha-512基于

得到的输出格式:散列机制(sha-512 $6 ),随机盐(第二个美元符号$ASDF1234之后的8个字节),余数是有效载荷。

  • mkpasswd mkpasswd -m sha-512

    mkpasswdwhois包提供)

基于DES:

产生的输出格式:前2个字节是你的盐,余数是有效载荷。 整件事是你的哈希密码。

  • mkpasswd: mkpasswd (由whois包提供)
  • openssl: openssl passwd -crypt
  • perl: perl -e "print crypt('password', 'sa');"

    /!\选择你自己的随机双字节盐而不是'sa'

  • python: python -c 'import crypt; print crypt.crypt("password", "Fx")' python -c 'import crypt; print crypt.crypt("password", "Fx")'

    /!\选择你自己的随机双字节盐而不是"Fx"

Interesting Posts