手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >批量修改ssh配置的expect脚本
批量修改ssh配置的expect脚本
摘要:第一思路,用iptables把外网ssh的包DROP掉;第二思路,用tcpwrapper把sshd的allow写死;第三思路,修改sshd_...

第一思路,用iptables把外网ssh的包DROP掉;

第二思路,用tcpwrapper把sshd的allow写死;

第三思路,修改sshd_config,只监听内网请求。

由于一些说不清楚的原因,iptables的办法没法用;而tcpwrapper占用CPU资源较多;所以最后决定用第三种办法。

公司服务器比较多,而且根据随机登录查看的结果,sshd_config内容居然还太不一样~~手工干了一天,改了两组服务器后,终于下定决心要整个全自动脚本出来干活…… 目前的办法是这样的:

cat ssh.exp

复制代码 代码如下:

#!/usr/bin/expect -f

log_file exp.log

set timeout -1

set ipaddr [lrange $argv 0 0]

for {set i 1} {$i<4} {incr i} {

spawn ssh $ipaddr

expect {

"*password:" break

"to host" {sleep 2};

sleep 3

}

}

send "123456r"

expect "]#"

send "cd /etc/sshr"

send "cp sshd_config sshd_config.`date +%F-%T`.bakr"

send "sed -i /^ListenAddress.*$/d sshd_configr"

send "echo ListenAddress `/sbin/ifconfig eth0|awk '/inet /{print $2}'|awk -F: '{print $2}'` >> sshd_configr"

send "service sshd restartr"

send "exitr"

interact

cat do.sh

复制代码 代码如下:

#!/bin/sh

for ip in `cat ip.lst`

do

./ssh.exp $ip > /dev/null 2>&1

done

cat exp.log | grep host | awk '{print $5}'|sort|uniq >> errorip

echo "以下IP无法修改";cat errorip

【批量修改ssh配置的expect脚本】相关文章:

Linux下实现SNMP一键安装的Shell脚本

Linux更新Python版本及修改python默认版本的方法

大小写字母转换的shell脚本代码

阿里云主机一键安装lamp、lnmp环境的shell脚本分享

监控php-fpm并自动重启服务的shell脚本

Shell脚本中非交互式修改密码的两种方法

Bash脚本内置的调试方法技巧

消耗CPU资源的shell脚本

一个测试下载速度的shell脚本

shell结合expect写的批量scp脚本工具

精品推荐
分类导航