I need to write a script to be able to run cmds on our test servers in our secure, off-site lab. The problem is these test servers are behind a jump server/jump host. Manually, I either type:
bash$ ssh -A jumphost
jumphost$ ssh server1
or I edited my personal .ssh/config file to use the jump host
ForwardAgent yes
Host server1
ProxyCommand ssh -q jumphost nc <ip of server1> 22
to access them. How do I do this inside my script so that ssh doesn't stop/terminate at ssh -A jumphost?
I tried to run
ssh jumphost nc <ip of server1> 22 "ls /tmp"
or
ssh jumphost nc <ip of server1> 22
or
ssh -A jumphost nc <ip> 22
but it complains of a protocol mismatch. I don't control the jump host so I can't just leave scripts/programs at a common place for people to use. I also don't think IT will make a jump host for us to use exclusively.
Is there a way for me to run scripts thru a jump host? Thanks in advance for your help. If there isn't a way, I'll just tell IT they need to allow me to copy my scripts to the jump host b/c the experts on stackoverflow said it needed to be done =)
Something along the lines of:
ssh -At jumpserver ssh -At server1
should work. The -t
makes sure that a pseudo-tty is allocated where needed (it may not be necessary on the second one, but I don't have a setup where I can test that at the moment, and it won't hurt). This also has the benefit that when you exit from server1
, both sessions go away...