# phpman > man > ssh-keyscan(1)

> **TLDR:** Get the public SSH keys of remote hosts.
>
- Retrieve all public SSH keys of a remote host:
  `ssh-keyscan {{hostname}}`
- Retrieve all public SSH keys of a remote host listening on a specific port:
  `ssh-keyscan -p {{port}} {{hostname}}`
- Retrieve certain types of public SSH keys of a remote host:
  `ssh-keyscan -t {{rsa,dsa,ecdsa,ed25519}} {{hostname}}`
- Manually update the SSH known_hosts file with the fingerprint of a given host:
  `ssh-keyscan -H {{hostname}} >> ~/.ssh/known_hosts`

*Source: tldr-pages*

---

[SSH-KEYSCAN(1)](https://www.chedong.com/phpMan.php/man/SSH-KEYSCAN/1/markdown)            BSD General Commands Manual           [SSH-KEYSCAN(1)](https://www.chedong.com/phpMan.php/man/SSH-KEYSCAN/1/markdown)

## NAME
     **ssh-keyscan** — gather SSH public keys from servers

## SYNOPSIS
     **ssh-keyscan** [**-46cDHv**] [**-f** _file_] [**-p** _port_] [**-T** _timeout_] [**-t** _type_] [_host_ | _addrlist_ _namelist_]

## DESCRIPTION
     **ssh-keyscan** is a utility for gathering the public SSH host keys of a number of hosts.  It was
     designed to aid in building and verifying _ssh_known_hosts_ files, the format of which is docu‐
     mented in [sshd(8)](https://www.chedong.com/phpMan.php/man/sshd/8/markdown).  **ssh-keyscan** provides a minimal interface suitable for use by shell and perl
     scripts.

     **ssh-keyscan** uses non-blocking socket I/O to contact as many hosts as possible in parallel, so
     it is very efficient.  The keys from a domain of 1,000 hosts can be collected in tens of sec‐
     onds, even when some of those hosts are down or do not run [sshd(8)](https://www.chedong.com/phpMan.php/man/sshd/8/markdown).  For scanning, one does not
     need login access to the machines that are being scanned, nor does the scanning process involve
     any encryption.

     The options are as follows:

### -4

### -6

### -c

### -D
             as a [ssh(1)](https://www.chedong.com/phpMan.php/man/ssh/1/markdown) _known_hosts_ file.

### -f
             Read hosts or “addrlist namelist” pairs from _file_, one per line.  If ‘-’ is supplied
             instead of a filename, **ssh-keyscan** will read from the standard input.  Input is ex‐
             pected in the format:

             1.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4

### -H
             [ssh(1)](https://www.chedong.com/phpMan.php/man/ssh/1/markdown) and [sshd(8)](https://www.chedong.com/phpMan.php/man/sshd/8/markdown), but they do not reveal identifying information should the file's
             contents be disclosed.

### -p
             Connect to _port_ on the remote host.

### -T
             Set the timeout for connection attempts.  If _timeout_ seconds have elapsed since a con‐
             nection was initiated to a host or since the last time anything was read from that
             host, the connection is closed and the host in question considered unavailable.  The
             default is 5 seconds.

### -t
             Specify the type of the key to fetch from the scanned hosts.  The possible values are
             “dsa”, “ecdsa”, “ed25519”, or “rsa”.  Multiple values may be specified by separating
             them with commas.  The default is to fetch “rsa”, “ecdsa”, and “ed25519” keys.

### -v

     If an ssh_known_hosts file is constructed using **ssh-keyscan** without verifying the keys, users
     will be vulnerable to _man_ _in_ _the_ _middle_ attacks.  On the other hand, if the security model al‐
     lows such a risk, **ssh-keyscan** can help in the detection of tampered keyfiles or man in the mid‐
     dle attacks which have begun after the ssh_known_hosts file was created.

## FILES
     _/etc/ssh/ssh_known_hosts_

## EXAMPLES
     Print the RSA host key for machine _hostname_:

           $ ssh-keyscan -t rsa hostname

     Find all hosts from the file _ssh_hosts_ which have new or different keys from those in the
     sorted file _ssh_known_hosts_:

           $ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \
                   sort -u - ssh_known_hosts | diff ssh_known_hosts -

## SEE ALSO
     [ssh(1)](https://www.chedong.com/phpMan.php/man/ssh/1/markdown), [sshd(8)](https://www.chedong.com/phpMan.php/man/sshd/8/markdown)

     _Using_ _DNS_ _to_ _Securely_ _Publish_ _Secure_ _Shell_ _(SSH)_ _Key_ _Fingerprints_, RFC 4255, 2006.

## AUTHORS
     David Mazieres <<_dm@lcs.mit.edu_>> wrote the initial version, and Wayne Davison
     <<_wayned@users.sourceforge.net_>> added support for protocol version 2.

BSD                            November 30, 2019                           BSD
