Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Automatically setting user passwords

Posted on 2004-08-23
1
Medium Priority
?
199 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 21

Accepted Solution

by:
tfewster earned 750 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
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…
Suggested Courses

782 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