I need to access data from a server that is behind a proxy. Thus, I can normally ssh to the proxy and then ssh to the destination to perform administration. However, not sure how to achieve this in bash. I do have a local ssh alias that will tunnel through the proxy automatically when i "ssh destination", but this must be in my environment or something and not used by the script.
In essence, is it possible to "ssh proxy ssh destination $commmand" in bash? I have tried the this exact command and had no success.
Not exactly what you want, but if forwarding a port is out of the question, you could set up an SSH tunnel first:
And then
You can devise something that keeps the tunnel up at all times. A very crude way:
You can try adding these lines in your ~/.ssh/config
Then you will be able to run only ssh remote_server. The ip/url and user will be the ones defined in the file. It will first ssh to proxy as user proxy_user and use nc on that session to talk to the remote server.
In order to use the command you wrote, you have to manage the authentication from the proxy server to the destination server. You can create a key pair (with ssh-keygen) on the proxy server and then put the public key in the authorized_keys file of the destination server (in .ssh/ directory of the user you use).
After the key exchange, your "ssh proxy ssh destination $commmand" should work.