Skip to content

Avoid killing child processes by sshd after session ended #1642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
madcatdev opened this issue Jul 25, 2020 · 7 comments
Closed

Avoid killing child processes by sshd after session ended #1642

madcatdev opened this issue Jul 25, 2020 · 7 comments

Comments

@madcatdev
Copy link

madcatdev commented Jul 25, 2020

"OpenSSH for Windows" version
OpenSSH_for_Windows_8.1p1, running as current user (not as SYSTEM)

Server OperatingSystem
Windows 7 SP1 (Microsoft Windows [Version 6.1.7601])

Client OperatingSystem
Same

What is failing
SSHD kills every process it had created after session is ended. For example, I want to launch notepad.exe window, which will be kept on Server side after SSH session is ended. So, these are my steps:

  1. Connecting to the server with command "ssh MyServer cmd", where MyServer is alias in the config file.
  2. Launch notepad with "notepad". After this, notepad windows (and processes) appears on Server machine.
  3. Exiting session with Ctrl+C. Notepad windows disappears, as the same process does not exist anymore.

I tried to launch notepad.exe with "start" command, even with nohup from GNU-Coreutils, so notepad.exe
process parent didn't exist at moment when ssh session ends, but nothing works. It seems that sshd does
something like "Kill Process Tree" function in ProcessExplorer. How to avoid this and make children processes (notepad.exe in this case) persistent?

@jborean93
Copy link

This is as designed and works just like a POSIX host where when the session is exited the child processes are killed. In saying that you can do something like nohup for Windows, the simplest way is to use WMI to call Win32_Process Create like #1032 (comment). This spawns a process that is not associated with the ssh job so when that is killed the child processes still continue to run.

@madcatdev
Copy link
Author

Thank you very much.
However Powershell is not presented in Windows 7, so I wrote simple program which calls CreateProcessA function with CREATE_BREAKAWAY_FROM_JOB flag (in dwCreationFlags). Works perfectly.

@jufeng2006
Copy link

Hi madcatdev,
I also worked on Windows 7, I can't figure out how to calls CreateProcessA? If you could post your related codes, I would appreciate it very much!

@bagajjal
Copy link
Collaborator

@jufeng2006 - Refer to #1032 (comment)

@jufeng2006
Copy link

@bagajjal,
Thanks for your reply, I'm running the OpenSSH on windows7 and the powershell is 2.0, which don't support the command you mentioned.
Thanks anyway.

@jborean93
Copy link

Use Invoke-WMIMethod instead if you have a really old version of PowerShell. You are better off upgrading to a newer version of PowerShell though.

@jufeng2006
Copy link

@jborean93 ,
Thanks a lot for your suggestion, I will have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants