To access a windows machine remotely I have to tunnel through a ubuntu server of mine. To setup the tunnel I have
ssh -l root -C -L 9999:windowsmachine:23389 myserver
Then I have to open another console and run
rdesktop -u user -password -f localhost:9999
How can I combine these in a single command or script?
(Disclaimer: See comments for a more efficient solution.)
This is tricky for a number of reasons:
ssh
needs to run in the foreground to hold the connection open. This makes it challenging to do this within a single instance of a shell, because the second command needs to execute in parallel to it being foreground.ssh
command, because the connection will have closed by then. This means the resktop command will fire regardless of whether ssh authentication succeeded.rdesktop
command to not be interactive, it needs to supply the password in the command line. Storing the password in the script is a bad idea.Try something like this:
Adjust the sleep statement as needed. You may want to remove the /dev/null redirection until you're sure this works. You also may want to redirect STDERR.
A better approach relies on the terminal program you're using within X, or whether or not you're familiar with a terminal multiplexer. If your terminal program provides a way for you to invoke a command in a new tab, prefix
ssh
with the appropriate command for doing that. If you go the multiplexer route, use the syntax for invokingssh
in a new multiplexer window. Dealing with passwords prompts fromssh
in both cases is up to you.