I need to manage the passwd and shadow files on two linked machines in a
programmed manner. I have a shell script which, amongst other things, allows
the changing of any user's password by simplying calling passwd with the
user name. This script may be run on either of the two machines, and if a
user's password is changed, it must be changed on both machines (in this
situation, NIS is NOT an option). Root on either machine can carry out
unattended operations on the other machine using ssh and appropriate
authorisation file.
In principle, I should be able to do this by running usermod -p on box2
from box1 but there's a slight technical hitch - the characters used in the
encrypted password. There can be a number of $ symbols in an encrypted
password (these boxes are running RH6.2 - I presume these are MD5 passwords
or somesuch) , and I am having a hell of a job passing them to the other
machine. I can do it by hand by doing
ssh box2 usermod -p \\\$1abc\\\$2defghijk
but I can't for the life of me get it working for real in a script. What I
need to do conceptually is simply (from box1)
ssh box1 /usr/sbin/usermod -p `grep "^$USERNAME" /etc/shadow|awk -F: '{print $2}'`
but because the backquote substitution returns strings with embedded $
symbols the above simple line doesn't work. I tried including a call to sed
in the backquoted expression wherein I replaced $ with n\$ where n\ means a
number of \ - I tried 1, 2, 3, 4 . . . . . but nothing worked. I was
considering writing a couple of little Perl scripts to encode and decode the
encrypted passwords but I just now had a quick think, deciding that there
must be something which does this already, and I came up with mimencode so
I'd have something along the lines of
PASSWORD=`grep "^$USERNAME" /etc/shadow|awk -F: '{print $2}'|mimencode`
ssh box1 /usr/sbin/usermod -p `echo $PASSWORD|mimencode -u` $USERNAME
I haven't yet tried that, because I can't get at the boxes from here, but I
hope it will work. I trust mimencode is distributed with RH6.2 (I had this
thought while using a SuSE box) ? Any other suggestions are welcome,
particularly from AnteFacto employees :-)
Regards,
Niall
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!