Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
397
rated 0 times [  397] [ 0]  / answers: 1 / hits: 182685  / 3 Years ago, sun, august 8, 2021, 5:40:42

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?


More From » adduser

 Answers
6

Use the --gecos option to skip the chfn interactive part.


adduser --disabled-password --gecos "" username

It's all in the man page. Not the most obvious formulation tho.


--gecos GECOS
Set the gecos field for the new entry generated. adduser will
not ask for finger information if this option is given.

The GECOS field is a comma separated list as such: Full name,Room number,Work phone,Home phone, despite that man page mentions finger information Details - Wikipedia


Hope this helps you.


Update: for more recent (or upcoming) versions of adduser, the --gecos option is replaced by --comment.


--comment comment
Set the comment field for the new entry generated. adduser will
not ask for the information if this option is given. This field
is also known under the name GECOS field and contains informa‐
tion that is used by the finger command. This used to be the
--gecos option, which is deprecated and will be removed after
Debian bookworm. Valid Modes: adduser, adduser --system.

[#41051] Sunday, August 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diffeah

Total Points: 78
Total Questions: 130
Total Answers: 98

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;