Solved

Automatically setting user passwords

Posted on 2004-08-23
1
193 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle 12c RAC - naming conventions, standards & best practices 4 186
How to clone solaris 10 machine 33 130
unix in java example 9 62
mobaxterm not able to change directory 28 146
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

776 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