ssh secure, remote connectivity to distribute keys

 First, the need to enter a password to access the back-end server command to connect to the specified server more secure from malicious connection

  1. Create a key pair management information ends

    • ssh-keygen -t dsa  
    • ll /root/.ssh (to see if successfully created)

  2. distribute the public key information management side

    • ssh-copy-id -i /root/.ssh/id_dsa.pub [email protected] (target server address)
    • ssh-copy-id command principles
      01. ssh and remote host connection
      02. The transfer public key file to the remote host, /root/.ssh/
      save the public key file contents to /root/.ssh/authorized_keys (600) (only root user to see)

  Second, the script distribute multiple hosts public key (no scripting before ansible)

  1. Ignore enter confirmation:

    • ssh -o StrictHostKeyChecking=no

  2. Ignore password information:

    • yum install -y sshpass
    • sshpass -pxxxxx (root password) ssh xxx.xxx.xxx.xxx (server IP address information)
    • Scripting:

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

        {7,31,41} in IP for
        do
        echo "==================== 172.16.1. $ IP Start Key ======== fenfa ============ "
        sshpass -p123456 SSH-Copy-StrictHostKeyChecking ID = -i -o /root/.ssh/id_dsa.pub NO 172.16.1. $ & IP> / dev / null
        IF [$? -eq 0]
        the then
        echo "public key distribution success" / bin / to true
        echo ""
        the else
        echo "public key distribution failed" / bin / false
        echo ""
        fi
        DONE

 

Guess you like

Origin www.cnblogs.com/wobenwuxin/p/11272553.html