I'd like to use the adduser
command to add a user (with disabled password) via a shell script.
By default, adduser
prompts you for various values (e.g., Full Name). Is there any way to submit these values via command line? Or will I need to useradd
instead?
Use the
--gecos
option to skip thechfn
interactive part.It's all in the man page. Not the most obvious formulation tho.
The GECOS field is a comma separated list as such:
Full name,Room number,Work phone,Home phone
, despite that man page mentionsfinger information
Details - WikipediaHope this helps you.
useradd
can also add users and does not appear to have any form of prompting built in.-m
,--create-home
: Create user home directory-p
,--password
: Specify user password; skip to have it disabled-s
,--shell
: Default shell for logon userBlank will use default login shell specified by the
SHELL
variable in/etc/default/useradd
<user>
with the login name<encryptedPassword>
with the encrypted passwordGenerating a hashed password:
There are a lot of crypt3 implementations that can generate a hashed password. The whole thing is your hashed password.
Sha-512 Based
The resulting output format: the hash mechanism (
$6
for sha-512), the random salt (the eight bytes after the second dollar sign$ASDF1234
), remainder is the payload.mkpasswd
mkpasswd -m sha-512
(
mkpasswd
is provided by thewhois
package)DES based:
The resulting output format: first 2 bytes is your salt, remainder is the payload. The whole thing is your hashed password.
mkpasswd
(provided bywhois
package)openssl passwd -crypt
perl -e "print crypt('password');"
python3 -c 'import crypt; print(crypt.crypt("password"))'
You can combine what @ThorSummoner @Zoke are saying like so:
I'm doing this for my Jupyter docker-stack. It allows full headless setup in a Dockerfile.