Forrest logo
back to the ssh-keyscan tool

ssh:tldr:e7804

ssh: Retrieve all public ssh keys of a remote host listening on a specific port.
$ ssh-keyscan -p ${port} ${host}
try on your machine

The ssh-keyscan -p ${port} ${host} command is used to retrieve the public SSH host key of a remote server.

Here's a breakdown of the command:

  • ssh-keyscan is the name of the command-line utility used to gather SSH host keys.
  • -p ${port} is an optional parameter that specifies the port number on which the SSH server is running. ${port} is a placeholder for the actual port number.
  • ${host} is a placeholder for the hostname or IP address of the remote server.

When you execute this command, it connects to the specified remote server and retrieves its public SSH host key. This key is used to verify the authenticity of the server when establishing an SSH connection. The retrieved public key is then printed on the terminal for further use.

By scanning for and saving SSH keys, this command helps in preventing man-in-the-middle attacks by ensuring that the server you are connecting to is actually the one you intend to connect to.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the ssh-keyscan tool