1

In Windows, I create a scheduled task on Windows startup:

C:\cygwin64\bin\ssh.exe -R 2222:127.0.0.1:3389 user@PublicHost

to expose my rdp service on a public-ip server, and I can connect rdp successfuly, but I cannot find ssh.exe in task manager, and when I shutdown windows, sometimes the 2222 port of PublicHost is not released, so later I boot windows again, the ssh.exe will give me a warning, port forwarding failed.

Is there a way to ask PublicHost to release the port (I don't have root access on PublicHost)?

MadHatter
  • 79,770
  • 20
  • 184
  • 232
Kingzone Wong
  • 11
  • 1
  • 2

3 Answers3

1

I would suggest looking at ClientAliveCountMax and ClientAliveInterval sshd_config options - this would help sshd to detect the connection which went down in uncontrolled way and cleanup it in such case.

Tomek
  • 3,390
  • 1
  • 16
  • 10
0

Can you run ssh in the foreground so that you get a shell prompt and can just logout of the ssh session?

Because if windows is shutting down and terminating ssh.exe, it should close that port. And if it's not getting released by the server, sending your own kill signal will likely have the same effect (if you could find it in task manager).

Or perhaps you could login (manual or scripted) into the PublicHost and kill things on that side (like /bin/bash of your UID) so the connection is dropped?

Ryan Babchishin
  • 6,260
  • 2
  • 17
  • 37
  • When the windows is rebooted, I want the ssh.exe to be run even before I login. that's why I need a scheduled task. If I login to PublicHost, and kill all sshd related to the current user, all other normal ssh connection will also be dropped. – Kingzone Wong Sep 08 '16 at 16:34
0

If you just connect to port 2222 of PublicHost it should attempt to send traffic through the tunnel. This will time out (after a few minutes) or receive a reset response (immediately), which will result in the connection being closed and the sshd process exiting.

You do this using any number of tools, but here's one way to do it automatically from Windows:

C:\cygwin64\bin\ssh.exe user@PublicHost "echo x | nc 127.0.0.1 2222"
Tom Shaw
  • 3,752
  • 16
  • 23
  • I tried, it's OK, but you have to wait for a long-time timeout, and seems this timeout should be configured on PublicHost with root user? – Kingzone Wong Sep 10 '16 at 03:42