ssh distribution

ssh batch distribution:

在nfs-server服务器(分发机)上产生秘钥:(创建一个新用户liming)
ssh-keygen -t dsa   (/home/liming/.ssh/id_dsa   该目录存放着生成的秘钥)
[liming@nfs-server ~]$ ls -l .ssh/
total 8
-rw-------. 1 liming liming 668 Dec  2 15:44 id_dsa   (钥匙)
-rw-r--r--. 1 liming liming 608 Dec  2 15:44 id_dsa.pub (锁)

default port: (将锁发送给其他默认端口的服务器)
ssh-copy-id -i .ssh/id_dsa.pub liming@backup-server 

port:52113  (将锁分发给其他指定该端口的服务器)
ssh-copy-id  -i id_dsa.pub "-p 52113 [email protected]"

Other servers operate in the same way. After the secret key is authenticated, the NFS server does not need a password to the back, lamp, and lnmp servers
at this time . (Example: Look at the network card of the back server from nfs at this time <liming user>: ssh -p22 liming@backup -server /sbin/ifconfig ens33)

Then distribute the file:

scp -P22 hosts liming@backup-server:~      (将本地的hosts文件传到 back服务器的家目录下)

Batch distribution: (write script on nfs server)

优化ssh配置文件:/etc/ssh/sshd_config (如果ssh传输慢) 
加入: PermitRootLogin no
    PermitEmptyPasswords no
    UseDNS no
    GSSAPIAuthentication no

vim fenfa.sh

#!/bin/bash
. /etc/init.d/functions  #调用函数库(下面action的使用)

#如果没有参数,做出判断并给出提示:
if [ $# -ne 1 ]
    then
      echo "USAGE:$0 {FILENAME|DIRNAME}"
      exit 1
fi

for n in backup-server lamp01 lnmp02
do
    scp -P22 -r $1 liming@$n:~ &>/dev/null
    if [ $? -eq 0 ]
      then
        action "fenfa $1 ok" /bin/true
    else
        action "fenfa $1 ok" /bin/false
    fi

done

~
Test: sh fenfa.sh hosts

vim view.sh

#!/bin/bash
. /etc/init.d/functions

if [ $# -ne 1 ]
                then
                    echo "USAGE:$0 COMMAND"
                    exit 1
fi
for n in backup-server lamp01 lnmp02
do 
    echo ========$n========
                ssh -P22 oldgirl@$n $1
done

test:

sh view.sh "/sbin/ifconfig ens33"
sh view.sh "cat /etc/redhat-release"

Guess you like

Origin blog.51cto.com/14956085/2572581
ssh