Bug 2181353

Summary: ssh-agent.service does not work on first access
Product: [Fedora] Fedora Reporter: Florian Apolloner <florian>
Component: opensshAssignee: Dmitry Belyavskiy <dbelyavs>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 42CC: aodaki, crypto-team, dbelyavs, dwalsh, hegel666, hello, ian, jjelen, lkundrak, lslebodn, mattias.ellert, tm
Target Milestone: ---Keywords: Reopened
Target Release: ---Flags: fedora-admin-xmlrpc: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: openssh-10.0p1-2.fc43 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2025-05-19 09:10:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Florian Apolloner 2023-03-23 19:55:05 UTC
The package openssh-clients ships with two systemd files, namely /usr/lib/systemd/user/ssh-agent.service and /usr/lib/systemd/user/ssh-agent.socket

The service file has the following code:
ExecStartPre=/usr/bin/rm -f $SSH_AUTH_SOCK
ExecStart=/usr/bin/ssh-agent -a $SSH_AUTH_SOCK

As one can see it removes any existing $SSH_AUTH_SOCK and recreates it's own. The socket unit creates the socket and expects the target to support socket activation (which openssh does not support) and on the first access the service unit is started, deletes the socket and then start ssh-agent.

At this point the program that initially connected to the socket is broken/hanging (in my case this is keepassxc) because nothing will answer on that fd.

The relevant docs say (https://www.freedesktop.org/software/systemd/man/systemd.socket.html):

Note that the daemon software configured for socket activation with socket units needs to be able to accept sockets from systemd, either via systemd's native socket passing interface (see sd_listen_fds(3) for details about the precise protocol used and the order in which the file descriptors are passed) or via traditional inetd(8)-style socket passing (i.e. sockets passed in via standard input and output, using StandardInput=socket in the service file).

If ssh-agent doesn't support either of those options I think it shouldn't have a socket unit.

Comment 1 Dmitry Belyavskiy 2023-08-03 09:16:17 UTC
Anthony Rabbito, you've provided the ssh-agent.socket file in rhbz#2125576

Do you have any comments?

Comment 2 Ian Dall 2024-03-15 01:25:04 UTC
I see this as well. It applies just as well if run ssh on the command line and you have "AddKeysToAgent" set. The ssh-agent starts perfectly well. If you kill the client (say ^C to ssh) and then do it again, the second time it works fine because by then the agent has already started. A work around might be to just start ssh-agent as a reqular daemon instead of using socket activation.

Comment 3 Aoife Moloney 2024-05-07 16:02:27 UTC
This message is a reminder that Fedora Linux 38 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 38 on 2024-05-21.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '38'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 38 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 4 Aoife Moloney 2024-05-21 14:33:42 UTC
Fedora Linux 38 entered end-of-life (EOL) status on 2024-05-21.

Fedora Linux 38 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora Linux
please feel free to reopen this bug against that version. Note that the version
field may be hidden. Click the "Show advanced fields" button if you do not see
the version field.

If you are unable to reopen this bug, please file a new report against an
active release.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 5 Dmitry Belyavskiy 2024-05-23 11:25:22 UTC
Florian,
What is your proposal to resolve this issue& I don't think removing socket file is a good decision.

Comment 6 Florian Apolloner 2024-05-23 11:27:58 UTC
I honestly think that the socket file should be removed. One cannot simply bolt systemd socket activation on a service that doesn't support socket activation. The only workable fix in the longrun that I can imagine is adding socket activation to ssh-agent (Iirc this has recently been done for sshd, so it might not be off-limits for ssh-agent).

Comment 7 Marcin Bachry 2025-01-09 15:19:17 UTC
FYI ssh-agent socket activation will be supported in openssh v10: https://github.com/openssh/openssh-portable/commit/66e986880b2472fefaad781f10113b138b65ff27

Comment 8 Aoife Moloney 2025-04-25 10:05:14 UTC
This message is a reminder that Fedora Linux 40 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 40 on 2025-05-13.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '40'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 40 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 9 Dmitry Belyavskiy 2025-05-16 14:47:50 UTC
Florian, Marcin - I just landed 10.0p1 into rawhide. Could you please test the behavior and provide necessary adjustments to ssh-agent.socket/ssh-agent.service if necessary?

Comment 10 Florian Apolloner 2025-05-17 19:03:06 UTC
Hi Dmitry, I have upgraded to 10.0.p1 and adjust the service file as follows:
```
# Requires SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
# set in environment, handled for example in plasma via
# /etc/xdg/plasma-workspace/env/ssh-agent.sh
[Unit]
ConditionEnvironment=!SSH_AGENT_PID
Description=OpenSSH key agent
Documentation=man:ssh-agent(1) man:ssh-add(1) man:ssh(1)
Requires=ssh-agent.socket

[Service]
ExecStart=/usr/bin/ssh-agent -D
PassEnvironment=SSH_AGENT_PID
SuccessExitStatus=2
Type=simple

[Install]
Also=ssh-agent.socket
```

So essentially I removed `ExecStartPre`/`Environment` and `-a $SSH_AUTH_SOCK` from `ExecStart`. Seems to work fine.

Comment 11 Fedora Update System 2025-05-19 09:08:13 UTC
FEDORA-2025-7965866479 (openssh-10.0p1-2.fc43) has been submitted as an update to Fedora 43.
https://bodhi.fedoraproject.org/updates/FEDORA-2025-7965866479

Comment 12 Fedora Update System 2025-05-19 10:43:31 UTC
FEDORA-2025-7965866479 (openssh-10.0p1-2.fc43) has been pushed to the Fedora 43 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 13 Lukas Slebodnik 2025-07-30 12:57:05 UTC
The version for the bug is set to 42 and resolution is ERRATA.
But it was fixed just in 43. 

It would be nice either to really backport it to f42 or to fix bz fields.
Either closed as RAWHIDE or to change version.

Because it is not enough to ssh-agent.service due to missing commit https://github.com/openssh/openssh-portable/commit/66e986880b2472fefaad781f10113b138b65ff27

Comment 14 Red Hat Bugzilla 2025-11-28 04:25:03 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 120 days