Skip to content

Commit a9aa51f

Browse files
dodexahedronsdwheeler
authored andcommitted
Modernize workaround for OpenSSH bug in SSH-Remoting-in-PowerShell.md
Added an option that creates a symbolic link, for systems without 8.3 support and simplified the method to get the 8.3 name as a fallback.
1 parent 415c17f commit a9aa51f

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

reference/docs-conceptual/security/remoting/SSH-Remoting-in-PowerShell.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,41 @@ remote computer. And, you must enable **password** or **key-based** authenticati
8787
> PowerShell in SSH server mode.
8888
8989
> [!NOTE]
90-
> The default location of the PowerShell executable is `C:/progra~1/powershell/7/pwsh.exe`. The
91-
> location can vary depending on how you installed PowerShell.
90+
> The full path to the PowerShell executable can be found by running:
9291
>
93-
> You must use the 8.3 short name for any file paths that contain spaces. There's a bug in
94-
> OpenSSH for Windows that prevents spaces from working in subsystem executable paths. For more
95-
> information, see this [GitHub issue][09].
92+
> ```powershell
93+
> (Get-Command pwsh).Source
94+
>```
95+
>
96+
> Due to a bug in OpenSSH for Windows that prevents spaces from working in subsystem executable
97+
> paths, you must use a path containing no whitespace.\
98+
> For more information, see this [GitHub issue][09].
99+
>
100+
> One option is to create a symbolic link to the executable:
101+
>
102+
> ```powershell
103+
> New-Item -ItemType SymbolicLink -Path C:\ProgramData\ssh\ -Name pwsh.exe -Value (Get-Command pwsh.exe).Source
104+
> ```
105+
>
106+
> This places a symbolic link to the PowerShell executable in the same directory used by the OpenSSH server to
107+
> store the host keys and other configuration. The link can be updated if the path to the executable ever changes,
108+
> without also needing to update your sshd_config file.
109+
>
110+
> If you are unable to use a symbolic link, another option is to use DOS "8.3"-style short names for the components
111+
> of the path to the PowerShell executable. This requires that the legacy NTFS 8dot3name file system option is
112+
> enabled for the system and for the volume on which PowerShell is installed, and an 8.3 name must exist for all
113+
> path components. It is inadvisable to enable that option if it is not currently enabled, and doing so may be
114+
> restricted by group policy.
96115
>
97-
> The 8.3 short name for the `Program Files` folder in Windows is usually `Progra~1`. However,
98-
> you can use the following command to make sure:
116+
> You can use the following command to get the full 8.3 path to pwsh.exe:
99117
>
100118
> ```powershell
101-
> Get-CimInstance Win32_Directory -Filter 'Name="C:\\Program Files"' |
102-
> Select-Object EightDotThreeFileName
119+
> cmd.exe /Q /C "for %I in (`"$((Get-Command pwsh.exe).Source)`") do echo %~sI"
103120
> ```
104121
>
122+
> Example output on a system with PowerShell 7 Preview installed (may not be identical on all systems):
105123
> ```Output
106-
> EightDotThreeFileName
107-
> ---------------------
108-
> C:\progra~1
124+
> C:\PROGRA~1\POWERS~1\7-PREV~1\pwsh.exe
109125
> ```
110126
111127
Optionally, enable key authentication:

0 commit comments

Comments
 (0)