linux ssh 免密脚本

qiuxp / 2023-08-16 / 原文

#!/bin/bash
ip="$1"
pawd="123qwe!@#"
expect << EOF
set timeout 10
spawn ssh-copy-id -p60022 root@${ip}
expect {
        "yes/no" {send "yes\n"; exp_continue}
        "password:" {send "${pawd}\n"}
        }
send "exit\n"
expect eof
EOF

 

 

 

 

 

检测

ssh -p60022 root@192.168.1.1