• 【shell脚本】批量修改主机密码modify_passwd.sh和ssh配置文件sshd.config.sh


    [root@rhel8 shell]# vi modify_passwd.sh
    [root@rhel8 shell]# cat modify_passwd.sh 
    #!/bin/bash
    ##########################################################################
    # modify passwd                                                          #
    # by author tanbaobao 2020/06/22                                         #
    ##########################################################################
    
    # 清空文件
    # >ok.txt
    # >fail.txt
    
    read -p "Please enter a New Password: " NEW_PASS
    
    for ip in `cat ip.txt`
    do
        {
            ping -c1 -W1 $ip &>/dev/null
            if [ $? -eq 0 ];then
                ssh $ip "echo $NEW_PASS | passwd --stdin root"
                if [ $? -eq 0 ];then
                    echo "$ip" >>ok_`date +%F`.txt
                else
                    echo "$ip" >>fail_`date +%F`.txt
                fi
            else
                echo "$ip" >>fail_`date +%F`.txt
            fi
        }&
    done
    
    # 等待后台执行完成再输出后面内容
    wait
    echo "finish..."

    修改sshd配置文件脚本

    [root@rhel8 shell]# cat modify_sshd_config.sh 
    #!/bin/bash
    ##########################################################################
    # modify passwd                                                          #
    # by author tanbaobao 2020/06/22                                         #
    ##########################################################################
    
    for ip in `cat ip.txt`
    do
        {
            ping -c1 -W1 $ip &>/dev/null
            if [ $? -eq 0 ];then
                ssh $ip "sed -ri '/^#UseDNS/cUseDNS no' /etc/ssh/sshd_config"
                ssh $ip "sed -ri '/^GSSAPIAuthentication/cGSSAPIAuthentication yes' /etc/ssh/sshd_con
    fig"            ssh $ip "systemctl stop firewalld;systemctl disable firewalld"
                ssh $ip "sed -ri '/^SELINUX+/cSELINUX=disabled' /etc/sysconfig/selinux"
                ssh $ip "setenforce 0"
            fi
        }&
    done
    
    wait
    
    echo "all ok..."
  • 相关阅读:
    Linux系统与网络服务管理技术
    RAM阵列
    5月9日上海书城PPT畅销图书作者讲座
    计算变为人们梦寐以求的公用设施
    博文视点大讲堂28期 “助你赢在软件外包行业”成功举办
    WebService WSDL详解(上)
    Google十三年
    预编译头sadafx.h原理
    WebService WSDL详解(下)
    Ext 2.2在IE 9运行居然说Extall.j运行错误,晕死了
  • 原文地址:https://www.cnblogs.com/HeiDi-BoKe/p/13178591.html
Copyright © 2020-2023  润新知