Solved

Automatically setting user passwords

Posted on 2004-08-23
1
189 Views
Last Modified: 2013-12-27
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','CrypKey');
print $x'`::::::: >> /etc/shadow
etc...
0
Comment
Question by:Shtukka
1 Comment
 
LVL 20

Accepted Solution

by:
tfewster earned 250 total points
ID: 11869311
Q1: You could with an Expect script, but not with "standard" tools.


Q2:
grep -v "^username1:" /etc/shadow > /etc/shadow.tmp
(Note the ^ and the : in the grap pattern to ensure we get ONLY the line we want)

Then run your perl script on /etc/shadow.tmp

Alternatively:
awk -F: '{if ( USER == $1 ) {OFS=":"; print $1,PW,$3,$4,$5,$6,$7,$8,$9}}'  USER=username1 PW=$x  /etc/shadow > /etc/shadow.new
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now