linux ssh密码记录,Linux记录-ssh批量双向无密码登录

1批量ssh无密码登录

#!/bin/bash

set -e

user=root

password=xxx

ssh_port=22

iplist=(10.0.0.1 10.0.0.2 10.0.0.3)

cat >> /etc/sudoers.d/app << EOF

app ALL=(ALL) ALL

app ALL=(ALL) NOPASSWD: ALL

Defaults !env_reset

EOF

env_init(){

for ip in ${iplist[@]}

do

sshpass -p $password ssh -p $ssh_port $user@$ip << eeooff

groupadd -g 6000 apps

buseradd -s /bin/bash -G apps -m app

mkdir -p /usr/app

chown -R app:apps /usr/app

sed -i ‘/\^SELINUX/s/=.\*/=disabled/‘ /etc/selinux/config

setenforce 0

systemctl disable firewalld.service

systemctl stop firewalld.service

systemctl status firewalld.service

echo ‘* soft nofile 65536‘ >> /etc/security/limits.conf

echo ‘* hard nofile 65536‘ >> /etc/security/limits.conf

yum -y install sshpass gcc gcc-c++ make openssl-devel supervisor gmp-devel mpfr-devel libmpc-devel libaio numactl autoconf automake libtool libffi-devel snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan lsof lz4 lz4-devel

eeooff

sshpass -p $password scp -P $ssh_port /etc/sudoers.d/app $user@$ip:/etc/sudoers.d/app

done

}

ssh_init(){

for((i=0;i

do

sshpass -p $password ssh -p $ssh_port $user@${iplist[i]} << eeooff

su app -c "/usr/bin/ssh-keygen -t rsa -f /home/app/.ssh/id_rsa -P ‘‘;/bin/bash> /dev/null 2>&1"

su -c "echo>/home/app/.ssh/authorized_keys" app

su -c "cat /home/app/.ssh/id_rsa.pub >> /home/app/.ssh/authorized_keys" app

su -c "chmod 600 /home/app/.ssh/authorized_keys" app

eeooff

done

}

ssh_cp(){

for((i=0;i

do

num=$(echo ${#iplist[@]}-1 | bc)

if [[ $i -lt $num ]]

then

sshpass -p $password scp -P $ssh_port $user@${iplist[i]}:/home/app/.ssh/authorized_keys $user@${iplist[i+1]}:/home/app/.ssh/authorized_keys

sshpass -p $password ssh -p $ssh_port $user@${iplist[i+1]} << eeooff

chown -R app. /home/app

cat /home/app/.ssh/id_rsa.pub >> /home/app/.ssh/authorized_keys

eeooff

else

exit -1

fi

done

}

ssh_scp(){

for((i=${#iplist[@]}-1;;i--))

do

if [[ $i -gt 0 ]]

then

sshpass -p $password scp -P $ssh_port $user@${iplist[i]}:/home/app/.ssh/authorized_keys $user@${iplist[i-1]}:/home/app/.ssh/authorized_keys

else

exit -1

fi

done

}

env_init

ssh_init

ssh_cp

ssh_scp

原文:https://www.cnblogs.com/xinfang520/p/12784473.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值