Linux系统 SSH免密登入

mia

# ssh-keygen -t rsa

# cp -r /root/.ssh/d_rsa.pub  /root/.ssh/authorized_keys

# ssh-copy-id 192.168.2.176

 #!/bin/bash

Server_IP=

Server_Passwd=

function SSH_CopyID(){

expect -c "

        set timeout -1

        spawn ssh-keygen -t rsa

        expect {

                "(/root/.ssh/id_rsa):" { send " " ;}

                "(empty for no passphrase):" { send " ";}

                "again:" { send " " ;}

        };

        expect eof;

    "

expect -c "

        set timeout -1;

        spawn ssh-copy-id $Server_IP;

        expect {

                "yes/no" { send "yes " ;}

                "password:" { send "$Server_Passwd ";}

        };

        expect eof;

   "

}

SSH_CopyID

原文地址:https://www.cnblogs.com/devops-docker/p/11507172.html