I have an automated process that regularly SSHes to about 120 different machines over a VPN. Occasionally these machines switch IP addresses and use addresses that were previously used by different machines. This causes problems with host key checking when logging in via SSH.
To circumvent this, the process runs
ssh-keygen -R
to remove the host key from *known_hosts* prior to accessing each machine via SSH.
Unfortunately, each time this command runs, it seems to create a backup file of *known_hosts* named *known_hosts.ABCDEFGH* where "ABCDEFGH" is a random sequence of letters.
Recently I discovered approximately 750,000 of these backup files, taking up 34GB of hard drive space, on the server that runs the automated process.
Short of removing *known_hosts.\** each time I run ssh-keygen
, is there a way to prevent this build-up of files? I.e. is there a way to prevent ssh-keygen
from backing up the *known_hosts* file when it modifies it?
I've noticed this behavior on both Ubuntu 22.04 and on MacOS 13.6.6.
Asked by Jason C
(1585 rep)
Aug 14, 2024, 09:59 PM
Last activity: Aug 18, 2024, 04:37 PM
Last activity: Aug 18, 2024, 04:37 PM