Skip to content

Commit 657bad3

Browse files
committed
fix sonoma 14.6+ (#54)
1 parent 5d4e581 commit 657bad3

File tree

2 files changed

+103
-19
lines changed

2 files changed

+103
-19
lines changed

README.md

+101-15
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,100 @@ Used to accept (or deny) the use of the private key(s) added to the SSH authenti
1212
## Installation
1313

1414
### [Homebrew](https://brew.sh/)
15-
* Run:
1615

17-
```
18-
$ brew install theseal/ssh-askpass/ssh-askpass
19-
```
20-
* Follow caveats
16+
1. Run:
17+
18+
```sh
19+
brew install xquartz theseal/ssh-askpass/ssh-askpass
20+
```
21+
22+
See: [why install XQuartz?](#why-install-xquartz).
23+
24+
1. Log out and log in again.
25+
26+
1. Check that the `DISPLAY` environment variable is now set for `ssh-agent`
27+
by XQuartz in "inherited environment":
28+
29+
```sh
30+
launchctl print gui/$UID/com.openssh.ssh-agent
31+
```
32+
33+
1. On Apple Silicon Macs, run:
34+
35+
```sh
36+
sudo mkdir -p /private/var/select/X11/bin
37+
sudo ln -s /opt/homebrew/bin/ssh-askpass /private/var/select/X11/bin/
38+
```
39+
40+
On Intel Macs, run:
41+
42+
```sh
43+
sudo mkdir -p /private/var/select/X11/bin
44+
sudo ln -s /usr/local/bin/ssh-askpass /private/var/select/X11/bin/
45+
```
2146

2247
### [MacPorts](https://www.macports.org)
23-
* Install:
2448

25-
```
26-
$ sudo port install ssh-askpass
27-
```
49+
1. Install [XQuartz](https://www.xquartz.org/) from their packages.
50+
51+
MacPorts package this as well, but they've modified their install to
52+
disable the user LaunchAgent by default. The upstream package just works.
53+
54+
See: [why install XQuartz?](#why-install-xquartz).
55+
56+
1. Log out and log in again.
57+
58+
1. Check that the `DISPLAY` environment variable is now set for `ssh-agent`
59+
by XQuartz in "inherited environment":
60+
61+
```sh
62+
launchctl print gui/$UID/com.openssh.ssh-agent
63+
```
64+
65+
1. Run:
66+
67+
```sh
68+
sudo port install ssh-askpass
69+
sudo mkdir -p /private/var/select/X11/bin
70+
sudo ln -s /usr/local/bin/ssh-askpass /private/var/select/X11/bin/
71+
```
2872

2973
### Without Homebrew/MacPorts
3074

31-
* Run:
32-
```
33-
$ cp ssh-askpass /usr/local/bin/
34-
$ cp ssh-askpass.plist ~/Library/LaunchAgents/
35-
$ launchctl load -w ~/Library/LaunchAgents/ssh-askpass.plist
75+
1. Install [XQuartz](https://www.xquartz.org/) from their packages.
76+
77+
See: [why install XQuartz?](#why-install-xquartz).
78+
79+
1. Log out and log in again, so Apple's `ssh-agent` picks up the `DISPLAY`
80+
environment variables.
81+
82+
1. Check that the `DISPLAY` environment variable is now set for `ssh-agent`
83+
by XQuartz in "inherited environment":
84+
85+
```sh
86+
launchctl print gui/$UID/com.openssh.ssh-agent
87+
```
88+
89+
1. Install `ssh-askpass` to `/private/var/select/X11/bin/`:
90+
91+
```sh
92+
sudo mkdir -p /private/var/select/X11/bin
93+
sudo cp ssh-askpass /private/var/select/X11/bin/
94+
```
95+
96+
macOS has a broken symlink at `/usr/X11R6` to this path, so this
97+
creates it and puts `ssh-askpass` there.
98+
99+
You should now be able to use it with `ssh-add -c`.
100+
101+
If some tool does not look for `ssh-askpass` in
102+
`/usr/X11R6/bin/ssh-askpass`, you can a LaunchAgent to provide the path in
103+
the `SSH_ASKPASS` environment variable:
104+
105+
```sh
106+
cp ssh-askpass.plist ~/Library/LaunchAgents/
107+
launchctl load -w ~/Library/LaunchAgents/ssh-askpass.plist
36108
```
37-
* No need to log out; you can add keys to the agent with `ssh-add -c`
38109

39110
## Enabling keyboard navigation
40111
For security reasons ssh-askpass defaults to cancel since it's too easy to
@@ -54,6 +125,21 @@ ssh-keys. To make it easier to press `OK`:
54125

55126
Now you can press ⇥+spacebar to press `OK`.
56127

128+
## Why install XQuartz?
129+
130+
[Sonoma 14.6 and later block environment variables set by `launchctl setenv` from system LaunchAgents](https://github.com/theseal/ssh-askpass/issues/54#issuecomment-2264396356)
131+
(eg: Apple's `ssh-agent`).
132+
133+
However, these changes **do not** affect environment variables set by
134+
non-system LaunchAgents using `SecureSocketWithKey`.
135+
136+
When XQuartz' LaunchAgent is configured correctly, it instructs `launchd` to
137+
setup a socket and expose it with the `DISPLAY` environment variable.
138+
139+
This also means you can't rely on the `SSH_ASKPASS` environment variable to
140+
tell Apple's `ssh-agent` where `ssh-askpass` is - it must be available at
141+
the default location (`/usr/X11R6/bin/ssh-askpass`).
142+
57143
## License
58144
ISC license
59145

ssh-askpass.plist

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
<string>/bin/sh</string>
1212
<string>-pc</string>
1313
<string>#!/bin/sh
14-
launchctl setenv SSH_ASKPASS "${SSH_ASKPASS:=/usr/local/bin/ssh-askpass}"
15-
launchctl setenv SUDO_ASKPASS "${SUDO_ASKPASS:=/usr/local/bin/ssh-askpass}"
16-
launchctl list org.xquartz.startx >/dev/null || launchctl setenv DISPLAY "${DISPLAY:=ssh-askpass}" # only if not already set by Xquartz
17-
launchctl stop com.openssh.ssh-agent # to make sure it picks up environment
14+
launchctl setenv SSH_ASKPASS "${SSH_ASKPASS:=/private/var/select/X11/bin/ssh-askpass}"
15+
launchctl setenv SUDO_ASKPASS "${SUDO_ASKPASS:=/private/var/select/X11/bin/ssh-askpass}"
1816
</string>
1917
</array>
2018
<key>RunAtLoad</key>

0 commit comments

Comments
 (0)