码迷,mamicode.com
首页 > 系统相关 > 详细

Linux-remote change password (more)

时间:2015-09-08 00:23:27      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

1.creat managment Certification on Mangar Server
ssh-keygen -t rsa
2.creat client Certification on Client
ssh-keygen -t rsa
3.Copy certification from Server to Client and change name "authorized_keys"

scp /root/.ssh/id_rsa.pub 192.168.1.XX1:/root/.ssh/authorized_keys
scp /root/.ssh/id_rsa.pub 192.168.1.XX2:/root/.ssh/authorized_keys 

 

Mark:  pls backup the Public RSA key to other server   

 

4.install password creater " expect "
yum -y install expect expect-devel

+++++++++++++++mkpasswd++++++++++++++++++++++++++++
mkpasswd [args] [user]
where arguments are:
-l # (length of password, default = 10)
-d # (min # of digits, default = 2)
-c # (min # of lowercase chars, default = 2)
-C # (min # of uppercase chars, default = 2)
-s # (min # of special chars, default = 1)
-v (verbose, show passwd interaction)
-p prog (program to set password, default = passwd)
+++++++++++++++mkpasswd++++++++++++++++++++++++++++

5.vi /root/.ssh/ip_list.txt
192.168.1.XX1
192.168.1.XX2
192.168.1.XX3
...

6.vi /root/.ssh/Changepassword.sh

+++++++++++++++Changepassword.sh++++++++++++++++++++++++++++
#!/bin/bash
for IP in `cat /root/.ssh/ip_list.txt` #input client IP address
do
TMP_PWD=`mkpasswd -l 10 -C 3 -c 2 -d 2`
R_PWD=`echo ${TMP_PWD}`
echo "${TMP_PWD}" > .R_PWD.txt
if [ $? = 0 ] ; then
ssh $IP passwd root --stdin < .R_PWD.txt
echo -e "$(date "+%Y-%m-%d %H:%M:%S")\t${IP}\t${R_PWD}\t" >> R_Server.log
else
echo -e "$(date "+%Y-%m-%d %H:%M:%S")\t${IP} R_PWD.txt is create fail\tplease check!\t"
fi
if [ $? = 0 ] ; then
echo -e "$(date "+%Y-%m-%d %H:%M:%S")\tThe ${IP} passwd is modify OK\t"
else
echo -e "$(date "+%Y-%m-%d %H:%M:%S")\tThe ${IP} passwd is modify fail\tplease check!\t"
fi
done
echo "+++++++++++++IP and Password List+++++++++++++++++"
cat R_Server.log
rm .R_PWD.txt -f
+++++++++++++++Changepassword.sh++++++++++++++++++++++++++++

7.modify the X right

cd /root/.ssh/
chmod 777 changepassword.sh

8.run it
./changepassword.sh

Linux-remote change password (more)

标签:

原文地址:http://www.cnblogs.com/baxk/p/4790191.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!