Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Last active March 28, 2018 01:53
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mortymacs/0898c0adcd5e303ebecf38bc8b16e65f to your computer and use it in GitHub Desktop.
Save mortymacs/0898c0adcd5e303ebecf38bc8b16e65f to your computer and use it in GitHub Desktop.
Proxy Jump in SSH Connections

Create config file for ssh (my.conf):

Host Server1
    User root
    HostName 192.168.100.10
Host Server2
    User root
    HostName 192.168.100.5
Host Server3
    User root
    HostName 192.168.100.2
    ProxyJump Server1, Server2

Expect code (server3.sh):

#!/bin/sh
/usr/bin/expect <<EOF
spawn ssh -F my.conf Server3
expect "password"
send "PASSWORD-OF-SERVER-1\r"
expect "password"
send "PASSWORD-OF-SERVER-2\r"
expect "password"
send "PASSWORD-OF-SERVER-3\r"
expect "$"
interact
EOF

Try it:

$ server3.sh
@mortymacs
Copy link
Author

@mortymacs
Copy link
Author

scp sample command:

$ scp -F my.conf myfile Server3:/root/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment