Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatically setting user passwords

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

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