Tuesday, September 13, 2005
admin.sh
odin:~/bin# cat admin.sh
#!/bin/sh
securehost="root@10.0.0.33"
compare() {
THISPASS=`grep root: /etc/shadow`
#echo $THISPASS
NEWPASS=`ssh $securehost 'cat /security/newpass'`
#echo $NEWPASS
if [ ${THISPASS} = ${NEWPASS} ];then
echo "SAME"
exit 0
else
echo "DIFFER"
doshadow
fi
}
gennewkey() {
if [ -f ~/.ssh/id_rsa.pub ]; then
echo "RSA public key OK."
else
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
cat ~/.ssh/id_rsa.pub | ssh $securehost "cat >> .ssh/authorized_keys"
fi
}
doshadow () {
cp /etc/shadow /etc/shadow.full.bk
sed -e /^root:/d /etc/shadow.full.bk > /etc/shadow.noroot
echo $NEWPASS > /etc/shadow
cat /etc/shadow.noroot >> /etc/shadow
rm /etc/shadow.full.bk
rm /etc/shadow.noroot
}
gennewkey
compare
exit 0
odin:~/bin#