Linux-remote change password (more)
2015-09-07 22:48
676 查看
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
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运维实战练习-2015年9月5日课程作业
- Linux计划任务
- Centos7 firewall常用命令总结
- Linux下磁盘常见错误分析与检测工具使用
- Linux内存管理之mmap详解
- linux 下查看硬盘坏道代码(转)
- Centos使用光盘作为本地yum源
- Linux系统安装
- Linux find查找
- linux运维实战练习-2015年8月30日课程作业(2)
- Linux操作系统桌面环境GNOME和KDE的切换
- linux 管理参数调节
- Linux中brk()系统调用,sbrk(),mmap(),malloc(),calloc()的异同
- linux运维实战练习-2015年8月30日课程作业
- Linux在批量服务器管理中实用的PS1命令提示符格式实现方法
- Linux中的SSH登录
- Linux/Mac/Windows换行符及对'\r'和'\n'的不同处理
- 在linux 配置matlab的 libsvm
- 马哥linux学习(linux任务计划)
- Linux下配置用msmtp和mutt发邮件