[Bug 3850] concurrent runs of ssh corrupts the known_hosts file

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Wed Jul 16 08:37:01 AEST 2025


https://bugzilla.mindrot.org/show_bug.cgi?id=3850

Darren Tucker <dtucker at dtucker.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dtucker at dtucker.net

--- Comment #1 from Darren Tucker <dtucker at dtucker.net> ---
I'm not sure ssh is behaving unreasonably here: you explicitly told
multiple parallel instances of it to modify the same file:

> while ! xargs -r -P ${jobs} -I '{}' ssh -4 -n -o StrictHostKeyChecking=accept-new -o ConnectTimeout=2 {}

One way to avoid this is to use the TOKEN expansion for
UserKnownHostsFile (which was added in v8.4) to put each host into its
own file based on hostname:

   UserKnownHostsFile ~/.ssh/known_hosts.d/%h

or hostkey:

   UserKnownHostsFile ~/.ssh/known_hosts.d/%k

either in your ~/.ssh/config or, in your use case, more likely as an -o
option to ssh in the script.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.
You are watching someone on the CC list of the bug.


More information about the openssh-bugs mailing list