Skip to content

Commit b998dd0

Browse files
committed
Editorial review and changes
1 parent a9aa51f commit b998dd0

File tree

1 file changed

+83
-95
lines changed

1 file changed

+83
-95
lines changed

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

Lines changed: 83 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -70,67 +70,65 @@ remote computer. And, you must enable **password** or **key-based** authenticati
7070
7171
1. Edit the `sshd_config` file located at `$Env:ProgramData\ssh`.
7272

73-
Make sure password authentication is enabled:
73+
- Make sure password authentication is enabled:
7474

75-
```
76-
PasswordAuthentication yes
77-
```
75+
```
76+
PasswordAuthentication yes
77+
```
7878
79-
Create the SSH subsystem that hosts a PowerShell process on the remote computer:
79+
- Create the SSH subsystem that hosts a PowerShell process on the remote computer:
8080
81-
```
82-
Subsystem powershell C:/progra~1/powershell/7/pwsh.exe -sshs -NoLogo
83-
```
81+
```
82+
Subsystem powershell C:/progra~1/powershell/7/pwsh.exe -sshs
8483
85-
> [!NOTE]
86-
> Starting in PowerShell 7.4, you no longer need to use the `-NoLogo` parameter when running
87-
> PowerShell in SSH server mode.
84+
> [!NOTE]
85+
> There is a bug in OpenSSH for Windows that prevents you from using a path with spaces for the
86+
> subsystem executable. There are two ways to work around this issue:
87+
>
88+
> - Use the Windows _8.3-style_ short name for the PowerShell executable path
89+
> - Create a symbolic link to the PowerShell executable that results in a path without spaces
90+
>
91+
> For more information, see this [GitHub issue][09].
8892
89-
> [!NOTE]
90-
> The full path to the PowerShell executable can be found by running:
91-
>
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.
115-
>
116-
> You can use the following command to get the full 8.3 path to pwsh.exe:
117-
>
118-
> ```powershell
119-
> cmd.exe /Q /C "for %I in (`"$((Get-Command pwsh.exe).Source)`") do echo %~sI"
120-
> ```
121-
>
122-
> Example output on a system with PowerShell 7 Preview installed (may not be identical on all systems):
123-
> ```Output
124-
> C:\PROGRA~1\POWERS~1\7-PREV~1\pwsh.exe
125-
> ```
126-
127-
Optionally, enable key authentication:
93+
You only need to get the 8.3-style name for the segment of the path that contains the space. By
94+
default PowerShell 7 is installed in `C:\Program Files\PowerShell\7\`. The 8.3-style name for
95+
`Program Files` should be `progra~1`. You can use the following command to verify the name:
12896
129-
```
130-
PubkeyAuthentication yes
131-
```
97+
```powershell
98+
Get-CimInstance Win32_Directory -Filter 'Name="C:\\Program Files"' |
99+
Select-Object EightDotThreeFileName
100+
```
101+
102+
The 8.3 name is a legacy feature of the NTFS file system that can be disabled. This feature
103+
must be enabled for the volume on which PowerShell is installed.
132104
133-
For more information, see [Managing OpenSSH Keys][05].
105+
Alternatively, you can create a symbolic link to the PowerShell executable that results in a
106+
path without spaces. This method is preferred because it allows you to update the link if the
107+
path to the PowerShell executable ever changes, without also needing to update your
108+
`sshd_config` file.
109+
110+
Use the following command to create a symbolic link to the executable:
111+
112+
```powershell
113+
$newItemSplat = @{
114+
ItemType = 'SymbolicLink'
115+
Path = 'C:\ProgramData\ssh\'
116+
Name = 'pwsh.exe'
117+
Value = (Get-Command pwsh.exe).Source
118+
}
119+
New-Item @newItemSplat
120+
```
121+
122+
This command creates the symbolic link in the same directory used by the OpenSSH server to store
123+
the host keys and other configuration.
124+
125+
- Optionally, enable key authentication:
126+
127+
```
128+
PubkeyAuthentication yes
129+
```
130+
131+
For more information, see [Managing OpenSSH Keys][05].
134132
135133
1. Restart the **sshd** service.
136134
@@ -153,34 +151,29 @@ remote computer. And, you must enable **password** or **key-based** authenticati
153151

154152
1. Edit the `sshd_config` file at location `/etc/ssh`.
155153

156-
Make sure password authentication is enabled:
154+
- Make sure password authentication is enabled:
157155

158-
```
159-
PasswordAuthentication yes
160-
```
156+
```
157+
PasswordAuthentication yes
158+
```
161159
162-
Optionally, enable key authentication:
160+
- Optionally, enable key authentication:
163161
164-
```
165-
PubkeyAuthentication yes
166-
```
162+
```
163+
PubkeyAuthentication yes
164+
```
167165
168-
For more information about creating SSH keys on Ubuntu, see the manpage for
169-
[ssh-keygen][08].
166+
For more information about creating SSH keys on Ubuntu, see the manpage for [ssh-keygen][08].
170167
171-
Add a PowerShell subsystem entry:
172-
173-
```
174-
Subsystem powershell /usr/bin/pwsh -sshs -NoLogo
175-
```
168+
- Add a PowerShell subsystem entry:
176169
177-
> [!NOTE]
178-
> The default location of the PowerShell executable is `/usr/bin/pwsh`. The location can vary
179-
> depending on how you installed PowerShell.
170+
```
171+
Subsystem powershell /usr/bin/pwsh -sshs -NoLogo
172+
```
180173
181-
> [!NOTE]
182-
> Starting in PowerShell 7.4, you no longer need to use the `-NoLogo` parameter when running
183-
> PowerShell in SSH server mode.
174+
> [!NOTE]
175+
> The default location of the PowerShell executable is `/usr/bin/pwsh`. The location can vary
176+
> depending on how you installed PowerShell.
184177
185178
1. Restart the **ssh** service.
186179
@@ -209,31 +202,27 @@ remote computer. And, you must enable **password** or **key-based** authenticati
209202
sudo nano /private/etc/ssh/sshd_config
210203
```
211204

212-
Make sure password authentication is enabled:
213-
214-
```
215-
PasswordAuthentication yes
216-
```
205+
- Make sure password authentication is enabled:
217206

218-
Add a PowerShell subsystem entry:
207+
```
208+
PasswordAuthentication yes
209+
```
219210
220-
```
221-
Subsystem powershell /usr/local/bin/pwsh -sshs -NoLogo
222-
```
211+
- Add a PowerShell subsystem entry:
223212
224-
> [!NOTE]
225-
> The default location of the PowerShell executable is `/usr/local/bin/pwsh`. The location can
226-
> vary depending on how you installed PowerShell.
213+
```
214+
Subsystem powershell /usr/local/bin/pwsh -sshs -NoLogo
215+
```
227216
228-
> [!NOTE]
229-
> Starting in PowerShell 7.4, you no longer need to use the `-NoLogo` parameter when running
230-
> PowerShell in SSH server mode.
217+
> [!NOTE]
218+
> The default location of the PowerShell executable is `/usr/local/bin/pwsh`. The location can
219+
> vary depending on how you installed PowerShell.
231220
232-
Optionally, enable key authentication:
221+
- Optionally, enable key authentication:
233222
234-
```
235-
PubkeyAuthentication yes
236-
```
223+
```
224+
PubkeyAuthentication yes
225+
```
237226
238227
1. Restart the **sshd** service.
239228
@@ -420,5 +409,4 @@ GitCommitId v6.0.0-alpha.17
420409
[06]: /windows-server/administration/openssh/openssh_overview
421410
[07]: /windows-server/administration/openssh/openssh_server_configuration
422411
[08]: http://manpages.ubuntu.com/manpages/xenial/man1/ssh-keygen.1.html
423-
[09]: https://github.com/PowerShell/Win32-OpenSSH/issues/784
424412
[10]: https://ubuntu.com/server/docs/service-openssh

0 commit comments

Comments
 (0)