Run adduser non-interactively
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?
adduser
add a comment |
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?
adduser
1
have a look at the man page for adduser. It will help you out.
– Zoke
Jan 9 '12 at 14:01
7
@Zoke I couldn't find the info I was looking for on the man page.
– Lorin Hochstein
Jan 9 '12 at 14:06
add a comment |
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?
adduser
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?
adduser
adduser
edited Jan 7 '13 at 7:30
Eliah Kagan
82.5k22227369
82.5k22227369
asked Jan 9 '12 at 13:54
Lorin HochsteinLorin Hochstein
1,98061929
1,98061929
1
have a look at the man page for adduser. It will help you out.
– Zoke
Jan 9 '12 at 14:01
7
@Zoke I couldn't find the info I was looking for on the man page.
– Lorin Hochstein
Jan 9 '12 at 14:06
add a comment |
1
have a look at the man page for adduser. It will help you out.
– Zoke
Jan 9 '12 at 14:01
7
@Zoke I couldn't find the info I was looking for on the man page.
– Lorin Hochstein
Jan 9 '12 at 14:06
1
1
have a look at the man page for adduser. It will help you out.
– Zoke
Jan 9 '12 at 14:01
have a look at the man page for adduser. It will help you out.
– Zoke
Jan 9 '12 at 14:01
7
7
@Zoke I couldn't find the info I was looking for on the man page.
– Lorin Hochstein
Jan 9 '12 at 14:06
@Zoke I couldn't find the info I was looking for on the man page.
– Lorin Hochstein
Jan 9 '12 at 14:06
add a comment |
2 Answers
2
active
oldest
votes
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.
44
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
5
+1--gecos
is very confusing.
– Trevor Sullivan
Apr 23 '17 at 22:39
add a comment |
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>
-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
- Substitute
<user>
with the login name - Substitute
<encryptedPassword>
with the encrypted password
Generating 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:
mkpasswd
(provided bywhois
package) - openssl:
openssl passwd -crypt
- perl:
perl -e "print crypt('password');"
- python:
python3 -c 'import crypt; print(crypt.crypt("password"))'
1
The options you mention don’t exist foradduser
on my (recent) version of Ubuntu.
– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
1
@ᴠɪɴᴄᴇɴᴛadduser
is distinct fromuseradd
, confusing I know.
– ThorSummoner
Sep 22 '15 at 21:01
1
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
1
@mum007 This is only general advice, try adding-v
or-vv
or-vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.
– ThorSummoner
Dec 3 '15 at 17:30
1
@KovacsAkos try this:sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
andsudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
|
show 3 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f94060%2frun-adduser-non-interactively%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
44
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
5
+1--gecos
is very confusing.
– Trevor Sullivan
Apr 23 '17 at 22:39
add a comment |
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.
44
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
5
+1--gecos
is very confusing.
– Trevor Sullivan
Apr 23 '17 at 22:39
add a comment |
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.
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.
edited Mar 29 '18 at 13:58
Anton Krosnev
1135
1135
answered Jan 9 '12 at 14:18
ZokeZoke
6,10621816
6,10621816
44
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
5
+1--gecos
is very confusing.
– Trevor Sullivan
Apr 23 '17 at 22:39
add a comment |
44
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
5
+1--gecos
is very confusing.
– Trevor Sullivan
Apr 23 '17 at 22:39
44
44
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
Yeah, I can see how I missed that. "gecos" is not an obvious description
– Lorin Hochstein
Jan 9 '12 at 14:26
5
5
+1
--gecos
is very confusing.– Trevor Sullivan
Apr 23 '17 at 22:39
+1
--gecos
is very confusing.– Trevor Sullivan
Apr 23 '17 at 22:39
add a comment |
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>
-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
- Substitute
<user>
with the login name - Substitute
<encryptedPassword>
with the encrypted password
Generating 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:
mkpasswd
(provided bywhois
package) - openssl:
openssl passwd -crypt
- perl:
perl -e "print crypt('password');"
- python:
python3 -c 'import crypt; print(crypt.crypt("password"))'
1
The options you mention don’t exist foradduser
on my (recent) version of Ubuntu.
– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
1
@ᴠɪɴᴄᴇɴᴛadduser
is distinct fromuseradd
, confusing I know.
– ThorSummoner
Sep 22 '15 at 21:01
1
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
1
@mum007 This is only general advice, try adding-v
or-vv
or-vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.
– ThorSummoner
Dec 3 '15 at 17:30
1
@KovacsAkos try this:sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
andsudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
|
show 3 more comments
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>
-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
- Substitute
<user>
with the login name - Substitute
<encryptedPassword>
with the encrypted password
Generating 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:
mkpasswd
(provided bywhois
package) - openssl:
openssl passwd -crypt
- perl:
perl -e "print crypt('password');"
- python:
python3 -c 'import crypt; print(crypt.crypt("password"))'
1
The options you mention don’t exist foradduser
on my (recent) version of Ubuntu.
– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
1
@ᴠɪɴᴄᴇɴᴛadduser
is distinct fromuseradd
, confusing I know.
– ThorSummoner
Sep 22 '15 at 21:01
1
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
1
@mum007 This is only general advice, try adding-v
or-vv
or-vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.
– ThorSummoner
Dec 3 '15 at 17:30
1
@KovacsAkos try this:sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
andsudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
|
show 3 more comments
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>
-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
- Substitute
<user>
with the login name - Substitute
<encryptedPassword>
with the encrypted password
Generating 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:
mkpasswd
(provided bywhois
package) - openssl:
openssl passwd -crypt
- perl:
perl -e "print crypt('password');"
- python:
python3 -c 'import crypt; print(crypt.crypt("password"))'
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>
-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
- Substitute
<user>
with the login name - Substitute
<encryptedPassword>
with the encrypted password
Generating 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:
mkpasswd
(provided bywhois
package) - openssl:
openssl passwd -crypt
- perl:
perl -e "print crypt('password');"
- python:
python3 -c 'import crypt; print(crypt.crypt("password"))'
edited 10 hours ago
answered Aug 31 '15 at 18:48
ThorSummonerThorSummoner
1,5061325
1,5061325
1
The options you mention don’t exist foradduser
on my (recent) version of Ubuntu.
– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
1
@ᴠɪɴᴄᴇɴᴛadduser
is distinct fromuseradd
, confusing I know.
– ThorSummoner
Sep 22 '15 at 21:01
1
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
1
@mum007 This is only general advice, try adding-v
or-vv
or-vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.
– ThorSummoner
Dec 3 '15 at 17:30
1
@KovacsAkos try this:sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
andsudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
|
show 3 more comments
1
The options you mention don’t exist foradduser
on my (recent) version of Ubuntu.
– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
1
@ᴠɪɴᴄᴇɴᴛadduser
is distinct fromuseradd
, confusing I know.
– ThorSummoner
Sep 22 '15 at 21:01
1
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
1
@mum007 This is only general advice, try adding-v
or-vv
or-vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.
– ThorSummoner
Dec 3 '15 at 17:30
1
@KovacsAkos try this:sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
andsudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
1
1
The options you mention don’t exist for
adduser
on my (recent) version of Ubuntu.– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
The options you mention don’t exist for
adduser
on my (recent) version of Ubuntu.– ᴠɪɴᴄᴇɴᴛ
Sep 22 '15 at 20:30
1
1
@ᴠɪɴᴄᴇɴᴛ
adduser
is distinct from useradd
, confusing I know.– ThorSummoner
Sep 22 '15 at 21:01
@ᴠɪɴᴄᴇɴᴛ
adduser
is distinct from useradd
, confusing I know.– ThorSummoner
Sep 22 '15 at 21:01
1
1
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
Oops, indeed missed that you use its almost namesake … isn’t there a BDFL protecting the command line namespace? ;p
– ᴠɪɴᴄᴇɴᴛ
Sep 23 '15 at 9:52
1
1
@mum007 This is only general advice, try adding
-v
or -vv
or -vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.– ThorSummoner
Dec 3 '15 at 17:30
@mum007 This is only general advice, try adding
-v
or -vv
or -vvv
to your ssh commands to see whats wrong and search your error messages here on SO or Google.– ThorSummoner
Dec 3 '15 at 17:30
1
1
@KovacsAkos try this:
sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
and sudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
@KovacsAkos try this:
sudo sed -i"" -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
and sudo service ssh restart
– JSBach
Apr 5 '17 at 9:01
|
show 3 more comments
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f94060%2frun-adduser-non-interactively%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
have a look at the man page for adduser. It will help you out.
– Zoke
Jan 9 '12 at 14:01
7
@Zoke I couldn't find the info I was looking for on the man page.
– Lorin Hochstein
Jan 9 '12 at 14:06