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

subsystem executable paths with "spaces" do not work #784

Open
philSixZero opened this Issue Jun 23, 2017 · 8 comments

Comments

Projects
None yet
5 participants
@philSixZero
Copy link

philSixZero commented Jun 23, 2017

"OpenSSH for Windows" version
v0.0.16.0

Server OperatingSystem
Windows 7 Enterprise

Client OperatingSystem
UBuntu 16.04 / 16.10

What is failing
Execution of powershell as subsystem.

Actual output
I configured the sshd_config file as follows:
Subsystem powershell C:\Program Files\PowerShell\6.0.0.17\powershell.exe -sshs -NoLogo -NoProfile

The sshd log file states following message regarding to the execution of the subsystem:
2956 11:50:35:760 debug1: Executing command: C:\\Program Files\\OpenSSH\\C:\\Program Files\\PowerShell\\6.0.0.17\\powershell.exe -sshs -NoLogo -NoProfile

This fails and the connection crushes. So I set the path in the sshd_config relatively to the OpenSSH folder:
Subsystem powershell ..\PowerShell\6.0.0.17\powershell.exe -sshs -NoLogo -NoProfile
which fixed the issue.

Is it only me experiencing this or had any of you the same issue?

@philSixZero philSixZero changed the title sshd_config subsystem path relatively to OpenSSH folder sshd_config subsystem path being relatively to OpenSSH folder Jun 23, 2017

@bagajjal

This comment has been minimized.

Copy link
Collaborator

bagajjal commented Jun 24, 2017

@philSixZero - I tried this and got a different error.

  1. What does this command do ?
    C:\Program Files\PowerShell\6.0.0.17\powershell.exe -sshs -NoLogo -NoProfile

  2. Here is the analysis,
    My sshdconfig -
    Subsystem powershell C:\Program Files\PowerShell\6.0.0.14\powershell.exe -sshs -NoLogo -NoProfile

When I tried to do ssh using "./ssh.exe localadmin@127.0.0.1 -s powershell".. my sshd.log shows that it executed the correct path but failed with different error message.

Logic - When you specify a relative path, we add the sshd.exe path. This is the reason it works fine.

sshd.log-
42292 17:54:16:346 debug1: subsystem: exec() C:\Program Files\PowerShell\6.0.0.14\powershell.exe -sshs -NoLogo -NoProfile
42292 17:54:16:346 Starting session: subsystem 'powershell' for localadmin from 127.0.0.1 port 34233 id 0
42292 17:54:16:346 debug3: pipe - r-h:412,io:00000280A9F525E0,fd:7 w-h:288,io:00000280A9F526D0,fd:8
42292 17:54:16:346 debug3: pipe - r-h:420,io:00000280A9F9BEE0,fd:9 w-h:416,io:00000280A9F9BFD0,fd:10
42292 17:54:16:346 debug3: pipe - r-h:428,io:00000280A9F9C0C0,fd:11 w-h:424,io:00000280A9F9C1B0,fd:12
42292 17:54:16:347 debug2: fd 7 setting O_NONBLOCK
42292 17:54:16:347 debug2: fd 8 setting O_NONBLOCK
42292 17:54:16:347 debug2: fd 9 setting O_NONBLOCK
42292 17:54:16:347 debug2: fd 10 setting O_NONBLOCK
42292 17:54:16:347 debug2: fd 11 setting O_NONBLOCK
42292 17:54:16:347 debug2: fd 12 setting O_NONBLOCK
42292 17:54:16:347 debug1: Executing command: C:\Program Files\PowerShell\6.0.0.14\powershell.exe -sshs -NoLogo -NoProfile
42292 17:54:16:348 debug3: Register child 00000000000001B4 pid 42444, 0 zombies of 0
42292 17:54:16:348 debug2: fd 3 setting TCP_NODELAY
42292 17:54:16:349 debug3: close - io:00000280A9F525E0, type:2, fd:7, table_index:7
42292 17:54:16:349 debug3: close - io:00000280A9F9BFD0, type:2, fd:10, table_index:10
42292 17:54:16:349 debug3: close - io:00000280A9F9C1B0, type:2, fd:12, table_index:12
42292 17:54:16:349 debug3: fd 9 is O_NONBLOCK
42292 17:54:16:349 debug3: fd 8 is O_NONBLOCK
42292 17:54:16:349 debug3: fd 11 is O_NONBLOCK
42292 17:54:16:349 debug3: send packet: type 99
42292 17:54:23:530 debug2: channel 0: read 103 from efd 11
42292 17:54:23:531 debug3: channel 0: discard efd
42292 17:54:23:542 debug2: channel 0: read<=0 rfd 9 len 0
42292 17:54:23:542 debug2: channel 0: read failed
42292 17:54:23:542 debug2: channel 0: close_read
42292 17:54:23:542 debug3: close - io:00000280A9F9BEE0, type:2, fd:9, table_index:9
42292 17:54:23:542 debug2: channel 0: input open -> drain
42292 17:54:23:542 debug2: channel 0: read 0 from efd 11
42292 17:54:23:542 debug2: channel 0: closing read-efd 11
42292 17:54:23:542 debug3: close - io:00000280A9F9C0C0, type:2, fd:11, table_index:11
42292 17:54:23:542 debug2: channel 0: ibuf empty
42292 17:54:23:542 debug2: channel 0: send eof
42292 17:54:23:542 debug3: send packet: type 96
42292 17:54:23:542 debug2: channel 0: input drain -> closed
42292 17:54:23:547 debug3: zombie'ing child at index 0, 0 zombies of 1
42292 17:54:23:547 debug1: Received SIGCHLD.
42292 17:54:23:547 debug3: Unregister child at index 0, 1 zombies of 1
42292 17:54:23:547 debug1: session_by_pid: pid 42444
42292 17:54:23:548 debug1: session_exit_message: session 0 channel 0 pid 42444
42292 17:54:23:548 debug2: channel 0: request exit-status confirm 0
42292 17:54:23:548 debug3: send packet: type 98
42292 17:54:23:548 debug1: session_exit_message: release channel 0
42292 17:54:23:548 debug2: channel 0: write failed
42292 17:54:23:548 debug2: channel 0: close_write
42292 17:54:23:548 debug3: close - io:00000280A9F526D0, type:2, fd:8, table_index:8
42292 17:54:23:548 debug2: channel 0: send eow
42292 17:54:23:548 debug3: send packet: type 98
42292 17:54:23:548 debug2: channel 0: output open -> closed
42292 17:54:23:548 debug2: channel 0: send close
42292 17:54:23:548 debug3: send packet: type 97
42292 17:54:23:548 debug3: channel 0: will not send data after close
42292 17:54:23:548 debug2: notify_done: reading
42292 17:54:23:548 debug3: channel 0: will not send data after close
42292 17:54:23:548 debug3: receive packet: type 97
42292 17:54:23:548 debug2: channel 0: rcvd close
42292 17:54:23:548 debug3: channel 0: will not send data after close
42292 17:54:23:548 debug2: channel 0: is dead
42292 17:54:23:548 debug2: channel 0: gc: notify user
42292 17:54:23:548 debug1: session_by_channel: session 0 channel 0
42292 17:54:23:548 debug1: session_close_by_channel: channel 0 child 0
42292 17:54:23:548 Close session: user localadmin from 127.0.0.1 port 34233 id 0
42292 17:54:23:548 debug3: session_unused: session id 0 unused
42292 17:54:23:548 debug2: channel 0: gc: user detached
42292 17:54:23:548 debug2: channel 0: is dead
42292 17:54:23:548 debug2: channel 0: garbage collecting
42292 17:54:23:548 debug1: channel 0: free: server-session, nchannels 1
42292 17:54:23:548 debug3: channel 0: status: The following connections are open:\r\n #0 server-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)\r\n
42292 17:54:23:548 debug3: WSARecv - WSARecv() ERROR: io:00000280A9F52290 10054
42292 17:54:23:548 debug3: recv - from CB ERROR:108, io:00000280A9F52290
42292 17:54:23:549 Read error from remote host 127.0.0.1 port 34233: Unknown error
42292 17:54:23:549 debug1: do_cleanup

@bagajjal

This comment has been minimized.

Copy link
Collaborator

bagajjal commented Jun 24, 2017

SSHD receive SIGCHLD from the ssh client so it closed the connection.

42292 17:54:23:530 debug2: channel 0: read 103 from efd 11
42292 17:54:23:531 debug3: channel 0: discard efd
42292 17:54:23:542 debug2: channel 0: read<=0 rfd 9 len 0
42292 17:54:23:542 debug2: channel 0: read failed
42292 17:54:23:542 debug2: channel 0: close_read
42292 17:54:23:542 debug3: close - io:00000280A9F9BEE0, type:2, fd:9, table_index:9
42292 17:54:23:542 debug2: channel 0: input open -> drain
42292 17:54:23:542 debug2: channel 0: read 0 from efd 11
42292 17:54:23:542 debug2: channel 0: closing read-efd 11
42292 17:54:23:542 debug3: close - io:00000280A9F9C0C0, type:2, fd:11, table_index:11
42292 17:54:23:542 debug2: channel 0: ibuf empty
42292 17:54:23:542 debug2: channel 0: send eof
42292 17:54:23:542 debug3: send packet: type 96
42292 17:54:23:542 debug2: channel 0: input drain -> closed
42292 17:54:23:547 debug3: zombie'ing child at index 0, 0 zombies of 1
42292 17:54:23:547 debug1: Received SIGCHLD.

@bagajjal

This comment has been minimized.

Copy link
Collaborator

bagajjal commented Jun 24, 2017

The same thing works if you specify cmd.exe in sshd_config
Subsystem mycmd C:\Windows\System32\cmd.exe

use
ssh user@ip -s mycmd

@philSixZero

This comment has been minimized.

Copy link

philSixZero commented Jun 27, 2017

Using a direct ssh session from Ubuntu to Windows with the "-s powershell" argument isn't working with this workaround. But somehow the "Enter-PSSession"-command in PowerShell 6 is only running with the relative path...

@manojampalam

This comment has been minimized.

Copy link
Collaborator

manojampalam commented Jun 28, 2017

The issue is with space " " in the subsystem executable path (ProgramFiles). I checked the code and the current implementation does not support it.

As a work around, you could create a symlink (with no spaces in its path) the following way and specify the link in the subsystem path
mklink /H c:\pslink.exe "C:\Program Files\PowerShell\6.0.0.17\powershell.exe"

Add this in sshd_config
Subsystem powershell C:\pslink.exe -sshs -NoLogo -NoProfile

@manojampalam manojampalam changed the title sshd_config subsystem path being relatively to OpenSSH folder subsystem executable paths with "spaces" do not work Jun 28, 2017

@bagajjal

This comment has been minimized.

Copy link
Collaborator

bagajjal commented Jun 29, 2017

tested on the unix environment. Unix has a way to escape the spaces in the path..
ex - /home/Ubuntu/test\ directory/ -> Here we escape the space in "test directory" using .

We need to find a way that suits windows.

@dantraMSFT

This comment has been minimized.

Copy link

dantraMSFT commented Aug 31, 2018

I hit the same issue on Server 2016 but found that neither mklink nor New-Item would create a usable symlink (The application to execute does not exist: 'C:\users\Public\pwsh.dll')

I ended up creating a directory link c:\powershell to resolve it.

@JustinGrote

This comment has been minimized.

Copy link

JustinGrote commented Dec 28, 2018

For those who came here from the MSFT documentation like I did, here's a script to automate the process on Windows.

https://gist.github.com/JustinGrote/72d7baaa6cc99691b7c4cb3caad54891

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment