Запуск rdesktop через туннель SSH в одной команде

3456
Matt Alexander

Я работаю ssh server -L 3392:192.168.1.138:3389в одном окне терминала, затем работаю rdesktop 127.0.0.1:3392в другом, чтобы подключиться к машине Windows через туннель SSH. Как я могу объединить это в одну команду, которую я могу запустить из ярлыка Gnome или что-то?

5

3 ответа на вопрос

2
Edward Anderson

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:

#!/bin/bash ssh server -L 3392:192.168.1.138:3389 -N & SSH_PID=$! sleep 5 # wait for the connection to establish rdesktop 127.0.0.1:3392 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.

2
Kadu

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

ssh server -fL 3392:192.168.1.138:3389 sleep 5 rdesktop 127.0.0.1:3392 

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.

Это гораздо лучший ответ, а также подходит в качестве однострочника! Ng Oon-Ee 6 лет назад 0
0
LtWorf

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.

Похожие вопросы