The best way to control Claude Code, Codex and more from any computer or phone
fix(ssh): stop asking for a password when the SSH agent can't sign (#23437)
Co-authored-by: maria-rcks <maria@kuuro.net>
Keith Vertrees committed
Nov 1, 2026 at 03:28 UTC
1c8c0d8845e498a0e985e3839fe00d7e2168e39b
4 files changed
+122
-3
packages/ssh/src/auth.test.ts
+34
-1
@@ -11,7 +11,7 @@ import * as Path from "effect/Path";
11
import * as HostProcess from "@t3tools/shared/HostProcess";
12
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
13
14
-import { buildSshChildEnvironment, isSshAuthFailure } from "./auth.ts";
14
+import { buildSshChildEnvironment, isSshAgentSigningFailure, isSshAuthFailure } from "./auth.ts";
15
16
describe("ssh auth", () => {
17
it.effect("detects ssh auth failures from common permission denied messages", () =>
@@ -30,6 +30,39 @@ describe("ssh auth", () => {
30
}),
31
);
32
33
+ it.effect("detects agent signing failures from current and pre-8.2 OpenSSH", () =>
34
+ Effect.sync(() => {
35
+ const denied = "julius@devbox: Permission denied (publickey,password).";
36
+ assert.isTrue(
37
+ isSshAgentSigningFailure(
38
+ new Error(
39
+ `sign_and_send_pubkey: signing failed for ED25519 "/home/julius/.ssh/id_ed25519" from agent: communication with agent failed\r\n${denied}`,
40
+ ),
41
+ ),
42
+ );
43
+ assert.isTrue(
44
+ isSshAgentSigningFailure(
45
+ new Error(`sign_and_send_pubkey: signing failed: agent refused operation\n${denied}`),
46
+ ),
47
+ );
48
+ assert.isTrue(
49
+ isSshAgentSigningFailure(
50
+ new Error(
51
+ `sign_and_send_pubkey: signing failed: communication with agent failed\n${denied}`,
52
+ ),
53
+ ),
54
+ );
55
+ assert.isFalse(
56
+ isSshAgentSigningFailure(
57
+ new Error(
58
+ `sign_and_send_pubkey: signing failed for ED25519-SK "/home/julius/.ssh/id_ed25519_sk": device not found\n${denied}`,
59
+ ),
60
+ ),
61
+ );
62
+ assert.isFalse(isSshAgentSigningFailure(new Error(denied)));
63
+ }),
64
+ );
65
+
66
it.effect("creates askpass env for cached password prompts", () =>
67
Effect.gen(function* () {
68
const fs = yield* FileSystem.FileSystem;
packages/ssh/src/auth.ts
+8
@@ -246,3 +246,11 @@ export function isSshAuthFailure(error: unknown): boolean {
246
/too many authentication failures/u.test(normalized)
247
);
248
}
249
+
250
+// A local agent signing failure cannot be remedied by the remote account password.
251
+export function isSshAgentSigningFailure(error: unknown): boolean {
252
+ const message = error instanceof Error ? error.message : String(error);
253
+ return /sign_and_send_pubkey: signing failed(?: for [^\n]* from agent:|: (?:agent refused operation|communication with agent failed))/u.test(
254
+ message,
255
+ );
256
+}
packages/ssh/src/tunnel.test.ts
+79
-1
@@ -15,7 +15,7 @@ import { HttpClient, HttpClientResponse } from "effect/http";
15
import { ChildProcess, ChildProcessSpawner } from "effect/process";
16
17
import * as SshAuth from "./auth.ts";
18
-import { SshCommandError } from "./errors.ts";
18
+import { SshCommandError, SshPasswordPromptError } from "./errors.ts";
19
import * as SshTunnel from "./tunnel.ts";
20
21
const makeSuccessfulProcess = (stdout: string) => {
@@ -260,6 +260,84 @@ describe("ssh tunnel scripts", () => {
260
}),
261
);
262
263
+ it.effect.each([
264
+ {
265
+ name: "does not ask for a password when the agent cannot sign an accepted key",
266
+ stderr:
267
+ 'sign_and_send_pubkey: signing failed for ED25519 "/home/julius/.ssh/id_ed25519" from agent: communication with agent failed\r\n' +
268
+ "julius@devbox: Permission denied (publickey,password).\r\n",
269
+ expectedPromptAttempts: [],
270
+ },
271
+ {
272
+ name: "asks for a password when signing failure has no agent provenance",
273
+ stderr:
274
+ 'sign_and_send_pubkey: signing failed for ED25519-CERT "key-cert.pub": agent refused operation\n' +
275
+ "julius@devbox: Permission denied (publickey,password).\n",
276
+ expectedPromptAttempts: [1],
277
+ },
278
+ {
279
+ name: "asks for a password when the server rejects every key",
280
+ stderr: "julius@devbox: Permission denied (publickey,password).\r\n",
281
+ expectedPromptAttempts: [1],
282
+ },
283
+ ])("$name", ({ stderr, expectedPromptAttempts }) =>
284
+ Effect.gen(function* () {
285
+ const promptAttempts: Array<number> = [];
286
+ const spawner = ChildProcessSpawner.make((command) =>
287
+ Effect.succeed(
288
+ commandArgs(command).includes("-G")
289
+ ? makeSuccessfulProcess("")
290
+ : {
291
+ ...makeSuccessfulProcess(""),
292
+ exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(255)),
293
+ stderr: Stream.make(new TextEncoder().encode(stderr)),
294
+ },
295
+ ),
296
+ );
297
+ const layer = Layer.mergeAll(
298
+ NodeServices.layer,
299
+ Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
300
+ Layer.succeed(HttpClient.HttpClient, testHttpClient),
301
+ Layer.succeed(NetService.NetService, testNetService),
302
+ Layer.succeed(
303
+ SshAuth.SshPasswordPrompt,
304
+ SshAuth.SshPasswordPrompt.of({
305
+ isAvailable: true,
306
+ request: (request) =>
307
+ Effect.sync(() => {
308
+ promptAttempts.push(request.attempt);
309
+ return null;
310
+ }),
311
+ }),
312
+ ),
313
+ SshTunnel.SshEnvironmentManager.layer({ resolveCliRunner: Effect.succeed(ARCHIVE) }),
314
+ );
315
+ yield* Effect.gen(function* () {
316
+ const manager = yield* SshTunnel.SshEnvironmentManager;
317
+ const result = yield* Effect.result(
318
+ manager.ensureEnvironment({
319
+ alias: "devbox",
320
+ hostname: "devbox",
321
+ username: null,
322
+ port: null,
323
+ }),
324
+ );
325
+ assert.isTrue(Result.isFailure(result));
326
+ assert.deepEqual(promptAttempts, expectedPromptAttempts);
327
+ if (Result.isFailure(result)) {
328
+ if (expectedPromptAttempts.length === 0) {
329
+ assert.instanceOf(result.failure, SshCommandError);
330
+ if (result.failure instanceof SshCommandError) {
331
+ assert.equal(result.failure.stderr, stderr);
332
+ }
333
+ } else {
334
+ assert.instanceOf(result.failure, SshPasswordPromptError);
335
+ }
336
+ }
337
+ }).pipe(Effect.provide(layer), Effect.scoped);
338
+ }),
339
+ );
340
+
341
it.effect.each(["local tunnel", "remote server"] as const)(
342
"waits for %s shutdown before reconnecting the same target",
343
(stalledStep) =>
packages/ssh/src/tunnel.ts
+1
-1
@@ -1454,7 +1454,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
1454
if (input.authSecret !== null) {
1455
authSecrets.delete(input.key);
1456
}
1457
- if (input.promptCount >= 2) {
1457
+ if (input.promptCount >= 2 || SshAuth.isSshAgentSigningFailure(input.error)) {
1458
return yield* input.error;
1459
}
1460