Index | Thread | Search

From:
noodle@pastanoggin.com
Subject:
ssh-add: print error "The agent has no identities." to stderr instead of stdout
To:
tech@openbsd.org
Date:
Sat, 08 Nov 2025 23:29:57 +0200

Download raw body.

Thread
I encountered this while writing a script that has the line:
 
keys=$(ssh-add -L) || exit 1

When the user had no keys stored in ssh-agent, the script exited
silently without printing "The agent has no identities."; The error
message was instead stored in the variable "keys" which is unnatural.
Other similar errors in the ssh-add.c log to stderr so it's safe to
align this printf too.

Index: ssh-add.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/ssh-add.c,v
retrieving revision 1.182
diff -u -p -r1.182 ssh-add.c
--- ssh-add.c   6 Nov 2025 01:31:11 -0000       1.182
+++ ssh-add.c   8 Nov 2025 21:18:54 -0000
@@ -519,7 +519,7 @@ list_identities(int agent_fd, int do_fp)
                        fprintf(stderr, "error fetching identities: %s\n",
                            ssh_err(r));
                else
-                       printf("The agent has no identities.\n");
+                       fprintf(stderr, "The agent has no identities.\n");
                return -1;
        }
        for (i = 0; i < idlist->nkeys; i++) {