Skip to content

Commit 3b310d8

Browse files
committed
Fix pipe permissions when running SSH agent as service on Windows
1 parent 135e2f5 commit 3b310d8

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

doc/README-Windows.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pip install <device>-agent
4646

4747
First, ensure you have Python installed, as described in the above section. Next, ensure you have Git installed:
4848
```
49-
winget install -e --id Git.Git
49+
winget install --id=Git.Git -e
5050
```
5151

5252
Create a directory for the source code, and clone the repository. Before running this command, you may want to change to a directory where you usually hold documents or source code packages.
@@ -80,7 +80,7 @@ Click on the "Add a feature" button. In the "Find an available optional feature"
8080

8181
Alternatively, you can install the latest version using WinGet:
8282
```
83-
winget install "openssh beta"
83+
winget install --id=Microsoft.OpenSSH.Beta -e
8484
```
8585

8686
If using an older version of Windows, you can install it using Chocolatey instead:
@@ -111,14 +111,18 @@ You will be required to authorize the use of the key on the device.
111111

112112
#### Running as a service
113113

114-
Adding services to Windows requires the use of a third-party tool. The recommended tool for this task is [NSSM](https://nssm.cc/download). It can be installed using the direct link, or via Chocolatey:
114+
Adding services to Windows requires the use of a third-party tool. The recommended tool for this task is [NSSM](https://nssm.cc/download). It can be installed using the direct link, or via WinGet:
115+
```
116+
winget install --id=NSSM.NSSM -e
117+
```
118+
Or using Chocolatey:
115119
```
116120
choco install nssm
117121
```
118122

119123
To set up the service, use the following commands:
120124
```
121-
nssm install "<device>-agent" <device>-agent "file:%USERPROFILE%/.ssh/<device>.pub" -f --sock-path=\\.\pipe\openssh-ssh-agent
125+
for /F "usebackq delims=" %A in (`where <device>-agent`) do nssm install "<device>-agent" "%A" """file:%USERPROFILE%/.ssh/<device>.pub""" -f --sock-path=\\.\pipe\openssh-ssh-agent
122126
nssm set "<device>-agent" DisplayName "Hardware Device SSH Authentication Agent"
123127
```
124128

@@ -146,7 +150,7 @@ The SSH authentication agent is designed to work with OpenSSH and compatible pro
146150

147151
You may download the installer directly, or install it using WinGet:
148152
```
149-
winget install winssh-pageant
153+
winget install --id=NathanBeals.WinSSH-Pageant -e
150154
```
151155

152156
Once installed, it will automatically run on startup, and deliver key requests to any running SSH agent. This requires the agent to be running as a service. See the section above.
@@ -157,7 +161,7 @@ To use GPG on Windows, you will need [Gpg4win](https://www.gpg4win.org/).
157161

158162
You can [download it directly](https://www.gpg4win.org/thanks-for-download.html) or install it via WinGet
159163
```
160-
winget install -e --id GnuPG.Gpg4win
164+
winget install --id=GnuPG.Gpg4win -e
161165
```
162166
Or using Chocolatey:
163167
```
@@ -266,6 +270,17 @@ Error: Couldn't find a setup script in C:\Users\MyUser\AppData\Local\Temp\easy_i
266270
```
267271
Your Python version may be out of date. Follow the Python installation instructions above. Restart your administrative shell if the update is not being detected.
268272

273+
If while running you receive the following error:
274+
```
275+
failed to create process.
276+
```
277+
This may be caused by Python being installed in a folder that contains a space in its name. You will need to uninstall and reinstall Python in a different folder:
278+
```
279+
winget uninstall python3
280+
winget install python3 --location="C:\python3"
281+
```
282+
After this, you will need to reinstall the agent.
283+
269284
If while running you receive the following error:
270285
```
271286
ModuleNotFoundError: No module named 'pywintypes'

libagent/win_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def __close(handle, disconnect):
5959
@staticmethod
6060
def create(name):
6161
"""Opens a named pipe server for receiving connections."""
62+
sa = win32security.SECURITY_ATTRIBUTES()
63+
sa.SetSecurityDescriptorDacl(True, None, False)
6264
handle = win32pipe.CreateNamedPipe(
6365
name,
6466
win32pipe.PIPE_ACCESS_DUPLEX | win32file.FILE_FLAG_OVERLAPPED,
@@ -67,7 +69,7 @@ def create(name):
6769
PIPE_BUFFER_SIZE,
6870
PIPE_BUFFER_SIZE,
6971
0,
70-
None)
72+
sa)
7173

7274
if handle == win32file.INVALID_HANDLE_VALUE:
7375
raise IOError('CreateNamedPipe failed ({0})'.format(win32api.GetLastError()))

0 commit comments

Comments
 (0)