Here is what I want to do :
- SSH to server 1
- inside server 1, SSH to server 2
- inside server 2, SSH to server 3
- inside server 3, run a single command ( like mysql )
- inside mysql console, run another command.
- then exit all the way to server 1
Is it possible to do a procedure like this ? If yes, then how ?
It is possible: Just execute
ssh(or a corresponding Python program you upload first) on each new hop, and when you finally reach the target, executemysql.However, it’s not advisable: You should never enter passwords (or worse, store private keys) for one server on another server. That means that if server 1 is ever compromised, your whole network is compromised.
Instead, use the first two ssh sessions to create tunnels to the next hop, either with the
-Loption of the command-linessh(which you probably need to use anyways, see above), or with paramiko.