~/.ssh/known_hosts 文件的使用场景
时间: 2023-11-11 16:02:51 浏览: 44
~/.ssh/known_hosts 文件用于存储已知的主机公钥信息,目的是为了防止中间人攻击,确保 SSH 连接的安全性。当你尝试通过 SSH 连接到一个主机时,SSH 客户端会检查该主机的公钥是否存在于 ~/.ssh/known_hosts 文件中,如果存在并且与该主机的实际公钥一致,则 SSH 连接会继续进行。如果该主机的公钥未被记录或者与已记录的公钥不一致,则 SSH 客户端会警告你该主机的公钥可能被篡改,需要你确认是否继续连接。
因此,~/.ssh/known_hosts 文件的使用场景主要涉及到 SSH 连接时的主机身份验证,可以有效地防止中间人攻击和其他安全问题。
相关问题
bad configuration option:userkonwnhostsfile~/.ssh/known_hosts
This error message is indicating that there is an issue with the configuration options in the SSH client configuration file. Specifically, it appears that there is a typo in the configuration option that specifies the location of the known hosts file.
The correct configuration option for the known hosts file is "UserKnownHostsFile", with the first letter of each word capitalized. The tilde symbol (~) should also be removed from the path, as this is not a valid character in the file path.
To resolve this error, you will need to edit the SSH client configuration file and correct the configuration option for the known hosts file. The configuration file is usually located at ~/.ssh/config and can be edited using a text editor such as nano or vim.
Here is an example of the correct configuration option for the known hosts file:
UserKnownHostsFile ~/.ssh/known_hosts
After making this change, save the configuration file and try connecting to the remote server again. The error should be resolved, and you should be able to connect to the server without any issues.
not found in /root/.ssh/known_hosts
这个错误通常是由于您连接的主机的 SSH 密钥没有被记录在您计算机的 known_hosts 文件中。为了解决这个问题,您可以尝试以下步骤:
1. 检查您是否正确地输入了主机名或 IP 地址。
2. 确认主机是否正在运行并且可以通过网络访问。
3. 如果您确定主机正在运行并且可以通过网络访问,请运行以下命令将主机的 SSH 密钥添加到 known_hosts 文件中:
ssh-keyscan -H hostname >> ~/.ssh/known_hosts
其中的 hostname 是您要连接的主机的名称或 IP 地址。
这将将主机的 SSH 密钥添加到您的计算机的 known_hosts 文件中,以便您可以连接到主机。
4. 如果您仍然遇到问题,请检查您的 known_hosts 文件是否已被损坏或删除。如果是这样,您可以删除该文件并再次运行上述命令来重新创建它。