Solved

Automatically setting user passwords

Posted on 2004-08-23
1
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

631 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