How to create user and password in one script for 100+ users
Clash Royale CLAN TAG#URR8PPP
up vote
-4
down vote
favorite
I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.
#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done
bash password command useradd multiuser
add a comment |Â
up vote
-4
down vote
favorite
I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.
#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done
bash password command useradd multiuser
1
Please do not use photos were text will do. It is not that difficult typing in that script.
â Rui F Ribeiro
Jan 23 at 12:37
2
I would look at changing the passwords for users in batch mode using chpasswd.
â Raman Sailopal
Jan 23 at 13:12
add a comment |Â
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.
#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done
bash password command useradd multiuser
I have written a script for adding and setting password for 100+ users. Eg: for setting password of the user I want to set in "user+123" format for all the users I.e user will change according to the username in password.
How can I write a script for this.
#!/bin/bash
for i in `more users.txt`
do
useradd $i;
echo "User $i added successfully"
passwd $("$i"123)
echo "Password added successfully for user"
done
bash password command useradd multiuser
edited Jan 23 at 12:51
Hunter.S.Thompson
4,50631334
4,50631334
asked Jan 23 at 12:33
Monika
11
11
1
Please do not use photos were text will do. It is not that difficult typing in that script.
â Rui F Ribeiro
Jan 23 at 12:37
2
I would look at changing the passwords for users in batch mode using chpasswd.
â Raman Sailopal
Jan 23 at 13:12
add a comment |Â
1
Please do not use photos were text will do. It is not that difficult typing in that script.
â Rui F Ribeiro
Jan 23 at 12:37
2
I would look at changing the passwords for users in batch mode using chpasswd.
â Raman Sailopal
Jan 23 at 13:12
1
1
Please do not use photos were text will do. It is not that difficult typing in that script.
â Rui F Ribeiro
Jan 23 at 12:37
Please do not use photos were text will do. It is not that difficult typing in that script.
â Rui F Ribeiro
Jan 23 at 12:37
2
2
I would look at changing the passwords for users in batch mode using chpasswd.
â Raman Sailopal
Jan 23 at 13:12
I would look at changing the passwords for users in batch mode using chpasswd.
â Raman Sailopal
Jan 23 at 13:12
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
#!/bin/bash
for i in $( cat users.txt ); do
useradd $i
echo "user $i added successfully!"
echo $i:$i"123" | chpasswd
echo "Password for user $i changed successfully"
done
This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $()
is a good alternative.
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
add a comment |Â
up vote
1
down vote
The other answers provide technical answers for how to do this. But please don't do this.
As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)
Instead, send each user a random password, or a token via email to be used to set a new password.
add a comment |Â
up vote
0
down vote
In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.
You can change number of users as per requirment
for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
If you have a text file in which you have specific usernames, you can use
for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
#!/bin/bash
for i in $( cat users.txt ); do
useradd $i
echo "user $i added successfully!"
echo $i:$i"123" | chpasswd
echo "Password for user $i changed successfully"
done
This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $()
is a good alternative.
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
add a comment |Â
up vote
2
down vote
#!/bin/bash
for i in $( cat users.txt ); do
useradd $i
echo "user $i added successfully!"
echo $i:$i"123" | chpasswd
echo "Password for user $i changed successfully"
done
This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $()
is a good alternative.
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
add a comment |Â
up vote
2
down vote
up vote
2
down vote
#!/bin/bash
for i in $( cat users.txt ); do
useradd $i
echo "user $i added successfully!"
echo $i:$i"123" | chpasswd
echo "Password for user $i changed successfully"
done
This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $()
is a good alternative.
#!/bin/bash
for i in $( cat users.txt ); do
useradd $i
echo "user $i added successfully!"
echo $i:$i"123" | chpasswd
echo "Password for user $i changed successfully"
done
This little script should be what you are looking for. It adds the user first, then proceeds to change the password. Avoid using backticks, as they are deprecated, $()
is a good alternative.
edited Jan 23 at 16:53
Alexander
5,57812043
5,57812043
answered Jan 23 at 12:55
Hunter.S.Thompson
4,50631334
4,50631334
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
add a comment |Â
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Please give a reason for the downvote, maybe I can learn something, something I did wrong?
â Hunter.S.Thompson
Jan 23 at 16:59
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
Where do you see that back ticks are deprecated? It says nothing about that in the official manual. gnu.org/software/bash/manual/bashref.html#Command-Substitution
â Nathan Adams
Aug 3 at 4:09
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
@NathanAdams, unix.stackexchange.com/a/126928/237568
â Hunter.S.Thompson
Aug 3 at 13:35
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
en.wikipedia.org/wiki/Deprecation
â Hunter.S.Thompson
Aug 3 at 13:40
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
@Hunter.S.Thompson Works like a charm , thanks alot
â somethingSomething
Aug 22 at 5:56
add a comment |Â
up vote
1
down vote
The other answers provide technical answers for how to do this. But please don't do this.
As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)
Instead, send each user a random password, or a token via email to be used to set a new password.
add a comment |Â
up vote
1
down vote
The other answers provide technical answers for how to do this. But please don't do this.
As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)
Instead, send each user a random password, or a token via email to be used to set a new password.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The other answers provide technical answers for how to do this. But please don't do this.
As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)
Instead, send each user a random password, or a token via email to be used to set a new password.
The other answers provide technical answers for how to do this. But please don't do this.
As soon as a threat actor sees the pattern, they could log in as any other user. (And even if you force a password change on first login, someone could lock out all of the other users.)
Instead, send each user a random password, or a token via email to be used to set a new password.
answered Jan 28 at 21:37
Royce Williams
635618
635618
add a comment |Â
add a comment |Â
up vote
0
down vote
In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.
You can change number of users as per requirment
for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
If you have a text file in which you have specific usernames, you can use
for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
add a comment |Â
up vote
0
down vote
In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.
You can change number of users as per requirment
for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
If you have a text file in which you have specific usernames, you can use
for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.
You can change number of users as per requirment
for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
If you have a text file in which you have specific usernames, you can use
for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
In below script i am creating 5 users like user1,user2,user3,user4,user5 and setting the pasword as "username+123" for each user Tested and it worked successfully.
You can change number of users as per requirment
for i in user1..5; do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
If you have a text file in which you have specific usernames, you can use
for i in $(cat users.txt); do useradd $i; passwd -d $i; echo $i"123" | passwd $i --stdin; done
edited Jan 23 at 16:54
Hunter.S.Thompson
4,50631334
4,50631334
answered Jan 23 at 14:24
Praveen Kumar BS
1,010128
1,010128
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
add a comment |Â
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
OP wants the users to have unique names, and the password should be $user123, your answer does not accommodate that.
â Hunter.S.Thompson
Jan 23 at 16:03
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
@Hunter.S.Thompson Edited the answer and changed as per the requirement and tested too . its working fine
â Praveen Kumar BS
Jan 23 at 16:49
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
I edited your answer to properly show what the OP needs to do when the usernames are in a textfile.
â Hunter.S.Thompson
Jan 23 at 16:55
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f419063%2fhow-to-create-user-and-password-in-one-script-for-100-users%23new-answer', 'question_page');
);
Post as a guest
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
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
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
1
Please do not use photos were text will do. It is not that difficult typing in that script.
â Rui F Ribeiro
Jan 23 at 12:37
2
I would look at changing the passwords for users in batch mode using chpasswd.
â Raman Sailopal
Jan 23 at 13:12