- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Writing script to modify passwd file
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
07-11-2005 12:43 AM
07-11-2005 12:43 AM
At our employer, it is standard practice to make 2 backups of the passwd file before adding/removing/modifying users. Any changes are made to one of the backup copies and then "verified" before replacing the passwd file with the modified version.
We had an incident last week where our lead operator did not make 2 copies and instead removed 70 users from the one backup copy and then copied that to passwd. The net result was that this individual made every excuse in the book and did not accept that they were the one who caused the problem, even though I had a copy of the history file which showed all command typed in from the command prompt since their session began.
Because of this, I was directed to find out if it possible, or if a script exists which would prompt the user, when making changes to the passwd file. For example, a script might be called: passwdchng
When executed, it would prompt for the user id:
Enter user id:
If the user exists, it would then ask if you would like to modify or delete the user. If the user doesn't exist, it will ask you if you would like to add the user.
If you select modify, it will then show the current settings:
1)Password: Displayed as hash (we're not using shadow passwords)
2)User ID:
3)Group ID:
4)User Name/Description:
5)Home Directory:
6)Shell:
You would select a number to change that value. If you select passwd, a routine would run resetting the password to whatever it needs to be and forcing the user to change it upon the next login.
The script would also contain logic that would prevent the enduser from modifying users that do not have a certain group ID.
Let me know your thoughts. Perhaps having them do all this through SAM would be the answer.
Solved! Go to Solution.
- Tags:
- passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 12:54 AM
07-11-2005 12:54 AM
Re: Writing script to modify passwd file
And what is the deal with the forums? Sometimes I can search and sometimes I can't.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 01:02 AM
07-11-2005 01:02 AM
Re: Writing script to modify passwd file
I don't know of anything standard that will do what you require, but it could be scripted. Does you lead operator have full root access? If so, there isn't anything you can do to force them to follow correct procedures.
Your best bet is to limit their access and use sudo to allow them to run pre-defined (and locked-down) scripts for this (or any other priviledged) task. In the past I have refused to have root access on servers when another group had root access. Its fairly easy to make this case when you have an issue as you described above.
If sam functionality is what you need, but don't want to let them have full access them restricted sam access can be set up.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 01:09 AM
07-11-2005 01:09 AM
Re: Writing script to modify passwd file
If you decide to go with power borker I can always help you with the scripts.
Thanks
Juan
- Tags:
- sudo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 01:13 AM
07-11-2005 01:13 AM
Re: Writing script to modify passwd file
I think it makes perfect sense that we look at limiting the operations priviledges.
Juan, please give me more information/website on "power broker",
Mike Keys
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 01:38 AM
07-11-2005 01:38 AM
SolutionHere is some links with info about the software
The company
http://www.symark.com/powerbroker.htm
Software installation and config
http://www.uidaho.edu/pb/pb27-05.htm#P778_57145
http://www.uidaho.edu/pb/pb27-13.htm#P1486_106950
http://www.uidaho.edu/pb/pb27-18.htm#P3949_245086
Take a look and you will see that this software is very helpfull to delegate limited root privileges. Also it keeps tracking of each user steps.
Thanks
Juan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 02:15 AM
07-11-2005 02:15 AM
Re: Writing script to modify passwd file
I see some replies in the forums which use menu-driven scripts written in perl. I also see the 'useradd', 'usermod' and 'userdel' commands that I can use to build by command line syntax.
Since I an very, very new to scripting, how do I pull the values from the /etc/passwd file for a particular user and store in variables?
Basically the structure of the program is as such.
Display Menu
A) Add a new user
M) Modify an existing user
R) Remove an existing user
D) Display this menu
X) Exit program and logoff
Program is called via sudo to track user and time called.
If A)then
Check to see that user does not already exist. If user exists then return message to user and prompt if they would like to Modify or Remove. If Modify or Remvoe is selected at this point, a check should be made to ensure that group ID matches acceptable group ID for which to make changes. Therefore, root and other ID's are protected. The user ID used should be the next user ID available.
If M) or R)
Get user info from /etc/passwd file, parsed and diplayed into its component parts displayed as a menu (only for Modify). For Remove, prompt user with an "are you sure" command before executing. For a Modify, allow user to select component to modify. Group ID can't be changed. Password can be reset from here as well (perhaps as option on Main Menu). Display "are you sure" prompt after finished with changes before modifying.
Any suggestions are welcome.
Mike Keys
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 02:57 AM
07-11-2005 02:57 AM
Re: Writing script to modify passwd file
(assumed teh username you want to modify is stored in variable $USER)
REC=`grep ^$USER /etc/passwd`
PWDHASH=`echo $REC|cut -d: -f2`
UID=`echo $REC|cut -d: -f3`
GID=`echo $REC|cut -d: -f4`
GECKOS=`echo $REC|cut -d: -f5`
HOMEDIR=`echo $REC|cut -d: -f6`
DEFSHELL=`echo $REC|cut -d: -f7`
then you can modify your record by modifying any of these values and reconstruct it as:
NEWREC=`printf $USER":"$PWDHASH":"$UID":"$GID":$GECKOS:"$HOMEDIR":"$DEFSHELL`
(make sure $GECKOS is inside the double quotes as it may have spaces embedded inside)
then
delete this line out of your /etc/passwd and append the modified version to the bottom as follows:
LINE=`grep -n ^$USER /etc/passwd|cut -d: -f1`
sed -e "${LINE}d" /etc/passwd > /tmp/passwd.fil
echo $NEWREC >> /tmp/passwd.fil
then dump the contents of the temporary file to the /etc/passwd
cat /tmp/passwd.fil > /etc/passwd
(do use 'cat' instead of 'mv' or 'cp' as this will preserve the file ownership and permissions of the /etc/passwd keeping you away from headaches in the future)
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 04:03 AM
07-11-2005 04:03 AM
Re: Writing script to modify passwd file
Thanks. Big help.
Since this is Perl. How do I do a comparison when modifying a user to ensure that user exists in passwd file?
If ($REC exists) {
do something
{
elsif ($REC not exist) {
print "User not found";
}
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 04:04 AM
07-11-2005 04:04 AM
Re: Writing script to modify passwd file
while true
do
clear
echo "A. Add New User"
echo "M. Modify an Existing User"
echo "R. Remove an Existing User"
echo "D. Display This Menu"
echo "X. Exit Program and Logoff"
echo " "
echo "Please make your selection then hit
read s
case $s in
"a"|"A")
clear; echo " Adding new user...\n\n" ;; # add new user commands here
"m"|"M")
clear; echo " Modifying user...\n\n";; # modify user commands here
"r"|"R")
clear; echo " Removing user...\n\n"
echo "do you want to remove the user's home directory and its contents y/[n]?"
read yn
if [[ $yn = "y" || $yn = "Y" ]]
then
userdel -r $USER
else
userdel $USER
fi ;;
"x"|"X")
clear; echo " Exiting Program.."; exit ;;
*)
# do nothing display the menu again
clear;;
esac
done
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 04:25 AM
07-11-2005 04:25 AM
Re: Writing script to modify passwd file
Are using a regular shell script? I was starting to write in Perl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 04:27 AM
07-11-2005 04:27 AM
Re: Writing script to modify passwd file
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 04:32 AM
07-11-2005 04:32 AM
Re: Writing script to modify passwd file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 04:32 AM
07-11-2005 04:32 AM
Re: Writing script to modify passwd file
"Since this is Perl. How do I do a comparison when modifying a user to ensure that user exists in passwd file?"
in ksh
(again username is in variable $USER assumption here)
grep ^$USER /etc/passwd; r=${?}
if [ $r -ne 0 ]
then
echo "$USER not found on this system"
fi
I think you can call a unix command using exec() command from inside a perl script but details of it eludes me.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2005 05:19 AM
07-11-2005 05:19 AM
Re: Writing script to modify passwd file
while ($string =~ m/regex/g) {
print "Found '$&'. Next attempt at character " . pos($string)+1 . "\n";
}
Hope helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2005 09:58 AM
07-12-2005 09:58 AM
Re: Writing script to modify passwd file
I'ave a similar script that I wrote a while back for adding/deleting/modifying users. It might be helpful to you or at the very least it could provide a framework on which you can build yours. This script is parameterized and menu-driven. Best of luck!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2005 12:52 PM
07-14-2005 12:52 PM
Re: Writing script to modify passwd file
to set their innital password to the above script.
You can use ssh for a more secure connection.