- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- I need a korn shell script to assign passwords
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 11:03 AM
08-28-2002 11:03 AM
I need a korn shell script to assign passwords
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 11:21 AM
08-28-2002 11:21 AM
Re: I need a korn shell script to assign passwords
You can do something like this:
...make a dummy account and encrypt a password...
# useradd -u 60000 -g 20 -s /usr/bin/false -m DUMMY
...make an encrypted password from a clear text one of your choice...
# passwd -F /tmp/passwd DUMMY
# CRYPTPASS=`awk -F: '{print $2}' /tmp/passwd`
# for USER in #...define the list...
# do
# sed /^${USER}:/"s%*%$CRYPTPASS%" /etc/passwd > /etc/passwd.new
# mv /etc/passwd.new /etc/passwd
# chmod 444 /etc/passwd
# done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 12:31 PM
08-28-2002 12:31 PM
Re: I need a korn shell script to assign passwords
the passwd -F ... does that add the password entry into /tmp/passwd instead of etc/passwd? If this sysetm doesn't have the "-F" option, can i just copy the line from etc/passwd and put it in the tmp/passwd file manually? will this still work?
Also, what does the sed /^${USER}... do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 12:52 PM
08-28-2002 12:52 PM
Re: I need a korn shell script to assign passwords
I left out one step inadvertantly. The fundamental script should look like this:
...make a dummy account and encrypt a password...
# useradd -u 60000 -g 20 -s /usr/bin/false -m DUMMY
...make an encrypted password from a clear text one of your choice...
# echo "DUMMY" > /tmp/passwd
# passwd -F /tmp/passwd DUMMY
# CRYPTPASS=`awk -F: '{print $2}' /tmp/passwd`
# for USER in #...define the list...
# do
# sed /^${USER}:/"s%*%$CRYPTPASS%" /etc/passwd > /etc/passwd.new
# mv /etc/passwd.new /etc/passwd
# chmod 444 /etc/passwd
# done
The file '/tmp/passwd' will contain an encrypted passwd suitable for extraction into '/etc/passwd'. I caputure this field in the variable CRYPTPASS.
I assume that you have backed-up your /etc/passwd file before you start.
The 'sed' command looks for the evaluated user in '/etc/passwd' anchored to the beginning of the line. Upon finding the proper line, the CRYPTPASS is substituted for the asterisk ("*") in the password field. Thus, the snippet of code I have provided assumes that the user account does *not* have a password associated with it. This could be changed to your taste.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 01:32 PM
08-28-2002 01:32 PM
Re: I need a korn shell script to assign passwords
the approach of using "sed" (or any other editing tool) directly onto your "/etc/passwd" is VERY dangerous!
Why not use "useradd" to create (locked) accounts, and then use the original "passwd(1M)" command to assign the passwords?
The only trick is to *embrace* that "passwd username" with "expect" - get it from the "HP-UX proting archives".
MUCH save IMHO...
FWIW,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 06:20 PM
08-28-2002 06:20 PM
Re: I need a korn shell script to assign passwords
/usr/sam/lbin/usermod.sam -p`echo "pass1234te" |/usr/lbin/makekey` username
This uses makekey to encrypt the password pass1234 and then assigns that password to user "username".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2002 11:36 PM
08-28-2002 11:36 PM
Re: I need a korn shell script to assign passwords
But I would like to say that you *can* edit the passwd file on a trusted system, and it can contain passwords, but you need to run pwconv to convert all the non-tcb passwords into the tcb.
Cheers!
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 06:51 AM
08-29-2002 06:51 AM
Re: I need a korn shell script to assign passwords
This is what I do in a script on HP-UX. I use this segment inside a user creation script that is on our operations menu so I don't have to add users to the system.
PASSWORD=generic
PGROUP=100
SGROUP=101,102,103
USER_NAME=$1
/usr/sam/lbin/useradd.sam -p "$(/util/Encrypt $PASSWORD 2>/dev/null)" -g $PGROUP $SGROUP -s /usr/bin/ksh -m $USER_NAME
/util/Encrypt is another shell script that does the following.
{
pwd=`pwd`
cd /util
cat > pswdconv$$.c << EO_source
main()
{
printf ("%s", crypt("$1", "dC"));
}
EO_source
cc -o pswdconv$$ pswdconv$$.c
echo `./pswdconv$$`
rm pswdconv$$ pswdconv$$.c
cd $pwd
}
Eric