ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically this script makes users with names next0, next1, next3 and so on up till 500.. The /dev/urandom part generates a random password and directs the output to /tmp/passwd.txt, but that goes on indefinitely, so head -c8 is used to specify the password length to be 8 characters (the -c8 does this)... The error that occurs is that it says --stdin is an unrecognized option.. My code succeeds in creating the users but their passwords fail to get created.
Last edited by justmy2cents; 05-25-2017 at 03:06 PM.
Can you please elaborate on what you mean by unchecked? I tried the code you posted and that produced the additional error "useradd: invalid home directory 'c'" Also nothng was written to the /tmp/passwd file, and no users were created..(my code creates users but their passwords fail to get created)
Last edited by justmy2cents; 05-26-2017 at 09:43 AM.
The error that occurs is that it says --stdin is an unrecognized option..
Your distribution/version does not have the passwd version that has --stdin option and will not accept a password from stdin. I do not recommend using the passwd command in a script for security reasons but you can use the chpasswd instead.
Your distribution/version does not have the passwd version that has --stdin option and will not accept a password from stdin. I do not recommend using the passwd command in a script for security reasons but you can use the chpasswd instead.
echo "password:name" | chpasswd
I'll give it a shot, I just recently discovered the chpasswd command earlier but it seemed like it was only for changing currently existing passwords.
Hello ladies and gents, I have this script that im not quite sure why it's not working. Any help would be appreciated, Thank You.
Code:
#!/bin/bash
for (( i=0; i<=500; i++ ))
do
useradd next$1
< /dev/urandom tr -dc A-Za-z0-9_|head -c8 > /tmp/passwd.txt
cat /tmp/passwd.txt|passwd --stdin user$i
done
rm -rf /tmp/passwd.txt -- someone is going to be doing a lot stiffening
through the /passwd file to get the users passwords so they can
give them to the person to login.
this (( i=0 and next$1 is not a match you have i (eye) for your number increment "next0, next1, next3 and so on up till 500" and 1 (one) for the variable name. Where is the value coming from?
this (( i=0 and next$1 is not a match you have i (eye) for your number increment "next0, next1, next3 and so on up till 500" and 1 (one) for the variable name. Where is the value coming from?
Don't know if anyone else caught that.
Good catch, the $1 in next$1 is supposed to be an $i..
Nothing you can do in bash can possibly work. passwd(1) does not read from standard input. This is intentional. It is for your protection. Passwords were never intended to be put into programs, or generated by programs. They were intended to be entered only by the fingers of an actual human being, with a functional brain, and never, ever written down anywhere. So before you continue, consider the possibility that the authors of passwd(1) were on to something, and you probably shouldn't be trying to script passwd(1) input.
Nonetheless, we get hordes of users asking how they can circumvent 35 years of Unix security. And we get people contributing their favorite security-removing "solutions" to this page. If you still think this is what you want, read on. http://mywiki.wooledge.org/BashFAQ/078
After reading that^ I realized I shouldn't be using the passwd command.. So I decided to use the mkpasswd command. This is my new code but I don't have the mkpasswd on hand yet to try it out.. Is there's any errors in this script that's obvious?
Code:
#!/bin/bash
mkdir -p /home/admin/useraccounts
for (( i=0; i<=500; i++ ))
do
useradd -m next$i -s /bin/bash -p "$(mkpasswd "$password")"
#echo the usernames and passwords to the admin account
echo -e "Username:next$i" > /home/admin/useraccounts/next$i
echo -e "Password:" >> /home/admin/useraccounts/next$i
done
Last edited by justmy2cents; 05-26-2017 at 03:12 PM.
After further reading the above article I realized that using mkpasswd is also not recommended.. I should instead use Kerberos.. So I think making a script such as this, to automatically generate passwords is insecure, and thus pointless.. This is because credentials should be separate from the script.. Please correct me if im wrong.. Nevertheless thanks you all for your suggestions..
very interesting.
it can cause significant delay.
i think it takes entropy from user activity? is it more random than /dev/urandom?
also, when i try to ramp up the password length (count > 6), the last characters are always the same, a '=' usually.
i wonder why.
oh, i see now, it works when i increase bs instead.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.