• How to SSH Batch Dispense


    SSH Batch Dispense

    1 Request

    Different machines must not root login with remote. All machines at user ygh_ssh(ordinary user).

    NFS_SERVICE send data and NFS_CLIENT_1, NFS_CLIENT_2 receive data. Don’t be asked password when send or receive data.

    2 Preparation machines and accounts

    Three Linux System machines, ant they can ping each.

    we use SSH to transmission data, because SSH can make sure safe with SSH2.x

    Hostname

    Network card

    Gateway

    Functions

    NFS_SERVICE

    192.168.98.132

    255.255.255.0

    Center sender

    NFS_CLIENT_1

    192.168.98.131

    255.255.255.0

    Receiver

    NFS_CLIENT_2

    192.168.98.134

    255.255.255.0

    Receiver

    Three Linux System all use the user name is “ygh_ssh” and uid=”666” to transmission data.

    3 Setting Private Key and Public Key

    The need is NFS_SERVICE can send data to NFS_CLIENT_1 and NFS_CLIENT_2, so private key is in NFS_SERVICE and public key is in NFS_CLIENT_1, NFS_CLIENT_2.

    3.1.1 create private in NFS_SERVICE

    Firstly, we make three Linux login “ygh_ssh”.

    Secondly, we use “ssh-keygen -t dsa” command to create private key and public key.

    you can give password, but you can also press “Enter” until end.

           -t sda indicates use “sda” algorithem.

     

    In “ygh_ssh” home directory, you will find a “.ssh” hidden directory

     

    The this directory, we will viem three main file:

    id_dsa:private key

    id_dsa_pub:public key

    Others file you can ingore if you haven’t

    So we shoud keep private to local and send public to service(NFS_CLIENT_1, NFS_CLIENT_2.

    ).

     

    we use this command “ssh-copy-id [-i [identity_file]] [user@]machine” to send public key to Service.

    for example:

    use follow commands to send public key to NFS_CLIENT_1

    ssh-copy-id -i /home/ygh_ssh/.ssh/id_dsa.pub "-p 52113 ygh_ssh@192.168.98.131"

    You should give ygh_ssh@192.168.98.131 password for the first time connection.

    If you repeat above actions, you will find it’s needn’t password.

     

    You also use this command to test whether you public key received. Using this command

    “ssh -p 52113 ygh_ssh@192.168.98.131” ,then you find you don’t give password and connect the NFS_CLIENT_1(you hostname change to NFS_CLIENT_1), it indelicate you success.

     

    we need to send public key to NSF_CLIENT_2 repeat above actions.

    In NFS_CLIENT_1 or NFS_CLIENT_2 /home/ygh_ssh/.ssh/

    you will view a file named “authorized_keys”, it is public key. It is same as the file id_dsa_qub at NFS_SERVICE /home/ygh_ssh/.ssh

     

    Now we can transmit date use NSF_SERVICE with NFS-CLIENT_2 and NFS_CLIENT_1 withput password!

    4 Testing batch send file

    4.1 Send Batch File to ygh_ssh Home Directory

    Firstly, we should write a shell scripts to help us send batch file.t

    # batch send file script author:ygh date:2017-01-09

    #file="$1"

    . /etc/init.d/functions

    for n in 131 134 123 122

    do

            scp -P52113 -rp $1 ygh_ssh@192.168.98.$n:~

    done

     

    In NFS_CLIENT_1 or NFS_CLIENT_2 /home/ygh_ssh/ you will find /data

     

    This indelicate data transmission success.

    4.2 Send to Batch File to arbitrary Directory

    We know, we use ygh_ssh only can write data to some directories that it is permitted, but if we want to transmit data to /root or /ect. How to do

    we you use this thoughts:

    1、 cp file or directory to ygh_ssh home directory

    2、 mv this file to the directory that you want set.

    3、 give ygh_ssh “sudo mv source file desDirectory”.

    In NFS_CLINET_1 or  NFS_CLINET_2 to give sudo mv authority to ygh_ssh

     

    Use follow shell scripts:

    # batch send file script author:ygh date:2017-01-09

    file="$1"

    remotedir="$2"

    . /etc/init.d/functions

    for n in 131 134 123 122

    do

            scp -P52113 -rp $1 ygh_ssh@192.168.98.$n:~ > /dev/null 2>&1 &&

            ssh -t -p 52113 ygh_ssh@192.168.98.$n "sudo /bin/mv ~/$file $remotedir" > /dev/null 2>&1

            if [ $? -eq 0 ]

            then

                    action "scp $file to ygh_ssh@192.168.98.$n:$remotedir is ok" /bin/true

            else

                    action "scp $file to ygh_ssh@192.168.98.$n:$remotedir is failed" /bin/false

            fi

    done

     

    In NSF_CLIENT_1 or NFS_CLIENT_2 /root, you will view

     

    5 Summary SSH Batch Send

    1、 It is single forward only from NFS_SERVICE to NFS_CLIENT_2 , NFS_CLIENT_1

    2、 It is based users, you better don’t span users

    3、 If you SSH connection is slow, you can retrieve following:

    http://oldboy.blog.51cto.com/2561410/1300964

  • 相关阅读:
    人脸识别数据库
    美赛
    排序算法
    个人作业——软件工程实践总结作业
    事后诸葛亮(团队)
    个人作业——软件产品案例分析
    Alpha冲刺总结
    Alpha冲刺——Day2
    Alpha冲刺——Day1
    I Know Alpha冲刺随笔集
  • 原文地址:https://www.cnblogs.com/yghjava/p/6268687.html
Copyright © 2020-2023  润新知