Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to chain from one terminal to another via SSH in one series of commands in linux? [closed]

I am attempting to set up an alias to get from my local box into our main server and then subsequently into an internal box. I'm setting up RSA keys to make this fast, but it would be really nice if I can alias the whole operation to a single short command. Split into parts, it would be two steps:

local> ssh x.x.x.x
x.x.x.x> ssh y.y.y.y
y.y.y.y>

I would prefer to use an alias "sshtoy" that accomplish both of these in one go, but I don't know how to chain these together. And with the RSA keys in place, I would magically end up on internal server y without all the typing. Any ideas? Can this be done?

like image 803
meesterguyperson Avatar asked Dec 15 '22 04:12

meesterguyperson


1 Answers

Okay. This one was pretty easy to find. Due diligence...

ssh -A -t server1 ssh -A -t server2 ssh -A server3

This will allow you to chain transparently from one server to the next, entering passwords as you go for each. With RSA keys set up and no passwords, you end up at server3 right away. To put this in an alias, you'd add the following to your ".bashrc" file.

alias sshto3="ssh -A -t server1 ssh -A -t server2 ssh -A server3"

Hope this helps someone.

like image 76
meesterguyperson Avatar answered Dec 21 '22 17:12

meesterguyperson