Shtukka
asked on
Automatically setting user passwords
I often need to set up a bunch of users with fixed passwords. I've got a script to create the users and everything but cannot set the passwords using this method - piping the password into the input for that script gives "permission denied". Q1 - Is there a way around this?
If we can't get past that, I've got a script to append the encrypted form of the correct passsword in /etc/shadow. However I don't know how to first remove the line that has the current user password, thus the user appears to have 2 passwords and everything screws up. So Q2 How can you search a file for a certain string and delete that line? (In the script below, I'd want to search /etc/shadow for the line with username1 in, delete that line, then run my script below)
FYI Here's the script I'm using to append the correct passwords:
echo username1:`perl -e '$x=crypt('userpwd1','Cryp Key');
print $x'`::::::: >> /etc/shadow
etc...
If we can't get past that, I've got a script to append the encrypted form of the correct passsword in /etc/shadow. However I don't know how to first remove the line that has the current user password, thus the user appears to have 2 passwords and everything screws up. So Q2 How can you search a file for a certain string and delete that line? (In the script below, I'd want to search /etc/shadow for the line with username1 in, delete that line, then run my script below)
FYI Here's the script I'm using to append the correct passwords:
echo username1:`perl -e '$x=crypt('userpwd1','Cryp
print $x'`::::::: >> /etc/shadow
etc...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.