首页 > 系统相关 >shell-实现一些小功能脚本

shell-实现一些小功能脚本

时间:2023-02-28 17:55:42浏览次数:63  
标签:脚本 功能 shell passwd rsa ssh sshpass root id

实现免密登录

vim  ./passwd
passwd="xxxxxxxx"

  

#!/bin/bash
source ./passwd
function secret_free_login(){
        ls  /root/.ssh/id_rsa.pub  &> /dev/null
        if [ $? -eq 0 ];then
                for i in ${node[@]}
                do
                        sshpass  -p  "$passwd"  ssh root@$i  "mkdir /root/.ssh &>/dev/null"
                        sshpass  -p  "$passwd"  scp   /root/.ssh/id_rsa.pub    root@$i:/root/.ssh/authorized_keys
                done
        else
                ssh-keygen -N '' -f /root/.ssh/id_rsa
                for p in ${node[@]}
                do
                        sshpass  -p  "$passwd"  ssh root@$p  "mkdir /root/.ssh &>/dev/null"
                        sshpass  -p  "$passwd"  scp  /root/.ssh/id_rsa.pub    root@$p:/root/.ssh/authorized_keys
                done
        fi
        echo "secret_free_login ok"
}

  

 

 

标签:脚本,功能,shell,passwd,rsa,ssh,sshpass,root,id
From: https://www.cnblogs.com/gsda/p/17165412.html

相关文章