Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running ssh server -L 3392: in one terminal window, then running rdesktop in another to connect to a Windows machine through an SSH tunnel. How can I merge this into one command that I can run from a Gnome shortcut or something?

share|improve this question
up vote 1 down vote accepted

I assume you have a password-less SSH key set up so that ssh does not prompt for a password.

You can use a bash script like this:

ssh server -L 3392: -N &
sleep 5 # wait for the connection to establish
kill $SSH_PID

I'm making an assumption here that rdesktop does not fork and return until the program ends. If it does, the SSH connection will die immediately. If that's true, you'd need to watch for running rdesktop processes, loop/sleep until they're all dead, and then close the SSH connection.

share|improve this answer

My "man ssh" says:

ssh [a bunch of options] [user@]hostname [command]

You could just use the command, but you seem to be using something different because your syntax doesn't match mine. Anyway check in the manpage there should be something to launch a command.

share|improve this answer

As an improvement to the above, you don't have to kill the SSH PID at the end.

ssh server -fL 3392: sleep 5  

The above will tell ssh to run a sleep 5 on the remove server and go to the background (-f). This will make the connection stay open for 5 seconds, which is enough time for the rdesktop command to run. The port forwarding will remain in place whilst there is traffic passing through, so as as soon as you exit the rdesktop the ssh should die automatically.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .