How to set user passwords using passwd without a prompt?
up vote
15
down vote
favorite
I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?
Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.
password
add a comment |
up vote
15
down vote
favorite
I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?
Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.
password
add a comment |
up vote
15
down vote
favorite
up vote
15
down vote
favorite
I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?
Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.
password
I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?
Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.
password
password
edited Apr 1 '16 at 4:09
muru
135k20289492
135k20289492
asked Nov 18 '11 at 11:06
Jake Petroules
178116
178116
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
16
down vote
accepted
Try usermod:
usermod --password PASSWORD USERNAME
The only thing is this needs a pre-encrypted password string which you'd have to generate first.
1
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
13
You can also use openssl to generate the encrypted password. For example:usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
add a comment |
up vote
6
down vote
You should look at the chpasswd
command (if available in your linux flavor):
echo 'userid:newpasswd' | chpasswd
Or, you can cat a file listing userid:passwd for each account on a separate line.
That's it.
add a comment |
up vote
0
down vote
You should use password aging, and set the users so that they must change their password on the first login. See this article.
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
add a comment |
up vote
0
down vote
Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.
$ openssl passwd -1 -salt 5RPVAd clear-text-passwd43
$1$5RPVAd$vgsoSANybLDepv2ETcUH7.
Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.
$ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root
Check it out in shadow file.
$ grep root /etc/shadow
root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::
add a comment |
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',
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%2f80444%2fhow-to-set-user-passwords-using-passwd-without-a-prompt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
16
down vote
accepted
Try usermod:
usermod --password PASSWORD USERNAME
The only thing is this needs a pre-encrypted password string which you'd have to generate first.
1
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
13
You can also use openssl to generate the encrypted password. For example:usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
add a comment |
up vote
16
down vote
accepted
Try usermod:
usermod --password PASSWORD USERNAME
The only thing is this needs a pre-encrypted password string which you'd have to generate first.
1
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
13
You can also use openssl to generate the encrypted password. For example:usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
add a comment |
up vote
16
down vote
accepted
up vote
16
down vote
accepted
Try usermod:
usermod --password PASSWORD USERNAME
The only thing is this needs a pre-encrypted password string which you'd have to generate first.
Try usermod:
usermod --password PASSWORD USERNAME
The only thing is this needs a pre-encrypted password string which you'd have to generate first.
answered Nov 18 '11 at 11:18
Caesium
11.3k33147
11.3k33147
1
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
13
You can also use openssl to generate the encrypted password. For example:usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
add a comment |
1
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
13
You can also use openssl to generate the encrypted password. For example:usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
1
1
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
...which I can generate using mkpasswd. Excellent, thanks!
– Jake Petroules
Nov 18 '11 at 11:27
13
13
You can also use openssl to generate the encrypted password. For example:
usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
You can also use openssl to generate the encrypted password. For example:
usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
– Eric Smith
Jan 16 '15 at 19:34
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:
usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work:
usermod --password $(openssl passwd -1 {password}) {username}
– BoCoKeith
Nov 29 at 15:36
add a comment |
up vote
6
down vote
You should look at the chpasswd
command (if available in your linux flavor):
echo 'userid:newpasswd' | chpasswd
Or, you can cat a file listing userid:passwd for each account on a separate line.
That's it.
add a comment |
up vote
6
down vote
You should look at the chpasswd
command (if available in your linux flavor):
echo 'userid:newpasswd' | chpasswd
Or, you can cat a file listing userid:passwd for each account on a separate line.
That's it.
add a comment |
up vote
6
down vote
up vote
6
down vote
You should look at the chpasswd
command (if available in your linux flavor):
echo 'userid:newpasswd' | chpasswd
Or, you can cat a file listing userid:passwd for each account on a separate line.
That's it.
You should look at the chpasswd
command (if available in your linux flavor):
echo 'userid:newpasswd' | chpasswd
Or, you can cat a file listing userid:passwd for each account on a separate line.
That's it.
edited Jan 2 '14 at 21:22
Eric Carvalho
41.1k17113144
41.1k17113144
answered Jan 2 '14 at 21:02
Allan
6111
6111
add a comment |
add a comment |
up vote
0
down vote
You should use password aging, and set the users so that they must change their password on the first login. See this article.
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
add a comment |
up vote
0
down vote
You should use password aging, and set the users so that they must change their password on the first login. See this article.
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
add a comment |
up vote
0
down vote
up vote
0
down vote
You should use password aging, and set the users so that they must change their password on the first login. See this article.
You should use password aging, and set the users so that they must change their password on the first login. See this article.
answered Nov 18 '11 at 21:37
waltinator
21.8k74169
21.8k74169
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
add a comment |
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
These intended to be FTP-only accounts, but good advice. ;)
– Jake Petroules
Nov 18 '11 at 22:49
add a comment |
up vote
0
down vote
Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.
$ openssl passwd -1 -salt 5RPVAd clear-text-passwd43
$1$5RPVAd$vgsoSANybLDepv2ETcUH7.
Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.
$ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root
Check it out in shadow file.
$ grep root /etc/shadow
root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::
add a comment |
up vote
0
down vote
Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.
$ openssl passwd -1 -salt 5RPVAd clear-text-passwd43
$1$5RPVAd$vgsoSANybLDepv2ETcUH7.
Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.
$ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root
Check it out in shadow file.
$ grep root /etc/shadow
root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::
add a comment |
up vote
0
down vote
up vote
0
down vote
Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.
$ openssl passwd -1 -salt 5RPVAd clear-text-passwd43
$1$5RPVAd$vgsoSANybLDepv2ETcUH7.
Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.
$ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root
Check it out in shadow file.
$ grep root /etc/shadow
root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::
Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.
$ openssl passwd -1 -salt 5RPVAd clear-text-passwd43
$1$5RPVAd$vgsoSANybLDepv2ETcUH7.
Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.
$ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root
Check it out in shadow file.
$ grep root /etc/shadow
root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::
answered Aug 31 at 21:29
Joon Byun
1
1
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f80444%2fhow-to-set-user-passwords-using-passwd-without-a-prompt%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