Skip to content

Managing Known Hosts

When you connect to a server for the first time using SFTP, the server presents its public key, and Connect tool asks, “Do you trust this server?” If you say yes, that key gets saved in the known_hosts file. The next time you connect, Connect tool checks that the server’s public key matches what’s saved in that file. If it doesn’t match—like in a case where the server has been reinstalled, or you’re being targeted in a man-in-the-middle attack. Connect tool will warn you about it. known_hosts file is located in the ~/.connect/ directory.

Checking known_hosts file - interactive mode

Section titled “Checking known_hosts file - interactive mode”

Connect tool will check the known_hosts file for the server’s public key when you try to connect. In interactive mode, if the key is not found, it will prompt you to add it.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p password
2025/06/25 13:23:28 INFO Testing connection to sftp://[email protected]
The key (SHA256:v/goXq57T++lsDmeYduLCRJEUzEqf9u9OybWiHt3VRc) of 10.0.0.24:22 is unknown. Do you want to add this key to known_hosts (y/n): y
2025/06/25 13:23:31 INFO Connection successful

If the key is found but does not match, it will warn you about the mismatch and allow you to update the key.

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p password
2025/06/25 13:25:11 INFO Testing connection to sftp://[email protected]
The key (SHA256:v/goXq57T++lsDmeYduLCRJEUzEqf9u9OybWiHt3VRc) of 10.0.0.24:22 does not match the one in known_hosts. Do you want to update this key in known_hosts (y/n): y
2025/06/25 13:25:17 INFO Connection successful

In batch mode, Connect tool will not prompt you for any input. If the key is not found, it will fail with an error.

Terminal window
$ connect send sftp -h 10.0.0.24 -l monitor01 -p password --file file1.zip --batch
2025/06/25 13:26:56 INFO Sending files to sftp://[email protected]:
2025/06/25 13:26:56 INFO Files to send: count=1
2025/06/25 13:26:56 ERROR Error while getting sftp session error=ssh: handshake failed: knownhosts: key is unknown file=file1.zip

In such case you need to add the key manually by using the connect test command:

Terminal window
$ connect test sftp -h 10.0.0.24 -l monitor01 -p password
2025/06/25 13:28:43 INFO Testing connection to sftp://[email protected]
The key (SHA256:v/goXq57T++lsDmeYduLCRJEUzEqf9u9OybWiHt3VRc) of 10.0.0.24:22 is unknown. Do you want to add this key to known_hosts (y/n): y
2025/06/25 13:28:47 INFO Connection successful