CentOS6CentOS7Ubuntu 一键部署 ssh 免密登录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS6CentOS7Ubuntu 一键部署 ssh 免密登录相关的知识,希望对你有一定的参考价值。

CentOS6、CentOS7、Ubuntu 一键部署 ssh 免密登录(ssh.py 文件)
192.168.1.5 为主机器,其他为控制机。
vim /home/shad.py

from fabric.api import run,env,parallel
env.hosts = [‘192.168.1.1‘, ‘192.168.1.2‘, ‘192.168.1.3‘]
env.user = ‘root‘
env.parssword = ‘123456‘
#@parallel
def name():
        run(‘apt install -y wget || yum install -y wget‘)
        run(‘wget http://192.168.1.5/ssh.sh‘)
        run(‘sh shad.sh‘)
CentOS6、CentOS7、Ubuntu 一键部署 ssh 免密登录(ssh.py 文件)
vim /var/www/html/ssh.sh
#!/bin/bash
name=`awk ‘NR==1{print $1}‘ /etc/issue`
if [ "$name" = "Ubuntu" ];then
sed -i ‘[email protected]#[email protected]@g‘ /etc/ssh/sshd_config
mkdir -p ~/.ssh
cat >>~/.ssh/authorized_keys<<EOF
**公钥**
EOF

sed -i ‘[email protected]#PasswordAuthentication [email protected] [email protected]‘ /etc/ssh/sshd_config
service sshd restart
elif [ "$name" = "CentOS" ];then
sed -i ‘[email protected]#PermitRootLogin [email protected] [email protected]‘ /etc/ssh/sshd_config
sed -i ‘[email protected]#[email protected]@g‘ /etc/ssh/sshd_config
sed -i ‘[email protected]#[email protected]@g‘ /etc/ssh/sshd_config
sed -i ‘[email protected]#[email protected]@g‘ /etc/ssh/sshd_config
mkdir -p ~/.ssh
cat >>~/.ssh/authorized_keys<<EOF
**公钥**
EOF

sed -i ‘[email protected] [email protected] [email protected]‘ /etc/ssh/sshd_config
service sshd restart
else
sed -i ‘[email protected]#PermitRootLogin [email protected] [email protected]‘ /etc/ssh/sshd_config
sed -i ‘[email protected]#[email protected]@g‘ /etc/ssh/sshd_config
mkdir -p ~/.ssh
cat >>~/.ssh/authorized_keys<<EOF
公钥
EOF
sed -i ‘[email protected] [email protected] [email protected]‘ /etc/ssh/sshd_config
service sshd restart
fi

以上是关于CentOS6CentOS7Ubuntu 一键部署 ssh 免密登录的主要内容,如果未能解决你的问题,请参考以下文章

▶▶▶▶shell一键部署◀◀◀◀(更新中)

▶▶▶▶shell一键部署◀◀◀◀(更新中)

K8S系列第十篇(一键部署MySQL主从复制)

▶▶▶▶shell一键部署◀◀◀◀(更新中)

shell脚本集合

shell脚本集合