ssh自动分发密匙脚本样板

本文介绍了一个Shell脚本,用于自动化配置本地YUM仓库并安装必要的软件包,如wget和sshpass。此外,脚本还实现了SSH密钥的自动化生成与分发,以简化在局域网内多台主机间的无密码SSH登录。

 

 
复制代码
#!/bin/bash
rom=/media/cdrom
dir=/etc/yum.repos.d
Use=$1
mima=$2
function yumj(){
[ -d "$rom" ] || mkdir -p "$rom"
/bin/umount /dev/sr0
/bin/mount /devsro0 $rom
[ -d "$dir" ] || mkdir -p "$dir"
cd "$dir" &&\
mv * /tmp/
/bin/cat > /etc/yum.repos.d/local.repo << fof
[local]
name=localrepo
basenurl=:///"$rom"
gpgcheck=0
enabled=1
fof
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq 0 ] || echo "本地yum出错"
which "wget"
rom=/media/cdrom
dir=/etc/yum.repos.d
Use=$1
mima=$2
function yumj(){
[ -d "$rom" ] || mkdir -p "$rom"
/bin/umount /dev/sr0
/bin/mount /devsro0 $rom
[ -d "$dir" ] || mkdir -p "$dir"
cd "$dir" &&\
mv * /tmp/
/bin/cat > /etc/yum.repos.d/local.repo << fof
[local]
name=localrepo
basenurl=:///"$rom"
gpgcheck=0
enabled=1
fof
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ -d "$rom" ] || mkdir -p "$rom"
/bin/umount /dev/sr0
/bin/mount /devsro0 $rom
[ -d "$dir" ] || mkdir -p "$dir"
cd "$dir" &&\
mv * /tmp/
/bin/cat > /etc/yum.repos.d/local.repo << fof
[local]
name=localrepo
basenurl=:///"$rom"
gpgcheck=0
enabled=1
fof
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq 0 ] || echo "本地yum出错"
which "wget"
#!/bin/bash
rom=/media/cdrom
dir=/etc/yum.repos.d
Use=$1
mima=$2
function yumj(){
[ -d "$rom" ] || mkdir -p "$rom"
/bin/umount /dev/sr0
/bin/mount /devsro0 $rom
[ -d "$dir" ] || mkdir -p "$dir"
cd "$dir" &&\
mv * /tmp/
/bin/cat > /etc/yum.repos.d/local.repo << fof
[local]
name=localrepo
basenurl=:///"$rom"
gpgcheck=0
enabled=1
fof
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq 0 ] || echo "本地yum出错"
which "wget"
[ $? -eq 0 ] || /usr/bin/yum -y install wget &>/dev/null
[ $? -eq 0 ] || (/bin/echo "wget error" && exit)
/usr/bin/wget http://mirrors.aliyun.com/repo/epel-6.repo
[ $? -eq 0 ] || (/bin/echo "yun源出错" && exit)
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq 0 ] || (/bin/echo "yun缓存错误" && exit)
/bin/echo "yum ok"
}

/bin/ping  -c 2 www.baidu.com &>/dev/null
[ $? -eq 0 ] || (/bin/echo "没网" && exit)
which  "sshpass" &>/dev/null
[ $? -eq 0 ] || /usr/bin/yum -y install sshpass &>/dev/null
if [ $? -ne 0 ] ;then
 yumj
 /usr/bin/yum -y install sshpass &>/dev/null || (echo "sshpass error" && exit)
fi
[ -d ~/.ssh ] || mkdir -p ~/.ssh ; chmod 700 ~./ssh
rm -rf ~/.ssh/id_*
ssh-keygen -t dsa -f ~/.ssh/id_dsa -P "" &>/dev/null
for i in 192.168.200.{1..245}
do
/bin/ping  -c 1 -i 0.1 $i &>/dev/null
if
        [ $? -eq 0 ];then
        sshpass -p $mima ssh-copy-id -i ~/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no $Use@$i"
        echo "$i 密匙成功"
fi
done

转载于:https://www.cnblogs.com/wangyinuo/p/9929675.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值