使用本地密钥通过 SSH 连接到跳板机并登录目标主机

使用本地密钥通过 SSH 连接到跳板机并登录目标主机

ssh -J user@jump_host:jump_port -i ~/.ssh/id_rsa -p dest_port user@destination_host:dest_port
ssh -J root@192.168.0.1:3022 -i ~/.ssh/id_rsa root@192.168.10.1 -p 4022

expect 脚本

#! /usr/bin/expect -f
set jump_port 3022
set jump_user root
set jump_host 192.168.0.1
#set jump_passwd
set timeout 30

set dest_host 192.168.10.1
set dest_user root
set dest_port 4022

set private_key ~/.ssh/id_rsa

spawn ssh -o "ProxyJump=$jump_user@$jump_host:$jump_port" $dest_user@$dest_host -p $dest_port

#expect {
    
    
#    "yes/no" {
    
    
#        send "yes\n"
#        expect "password"
#        send "$passwd\n"
#    }
#    "*assword" {
    
    
#        send "$passwd\n"
#    }
#}

interact

猜你喜欢

转载自blog.csdn.net/u010953692/article/details/131519182