git 如何从已知主机列表中删除永久添加的主机?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30490648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:15:02  来源:igfitidea点击:

How to remove permanently added host from list of known hosts?

gitssh

提问by ahndi

Currently I'm working on a project hosted by my university. We are using git as version control tool and when I connect to host 1st time it displays the following message: "Warning: Permanently added '...' (RSA) to the list of known hosts."

目前我正在从事我的大学主持的一个项目。我们使用 git 作为版本控制工具,当我第一次连接到主机时,它显示以下消息:“警告:将 '...' (RSA) 永久添加到已知主机列表中。”

  1. What does this exactly means?

  2. After the job is done, how can I remove this from the known hosts list? Is there any problem if I don't?

  1. 这究竟是什么意思?

  2. 工作完成后,如何从已知主机列表中删除它?如果我不这样做有什么问题吗?

回答by ahndi

If something has been added to 'list of known hosts' then in git bash shell under Windows and also under linux, an entry will have been added to the file known_hostswhich can be found in .ssh directory below your home directory.

如果某些内容已添加到“已知主机列表”中,那么在 Windows 和 linux 下的 git bash shell 中,将会在文件known_hosts 中添加一个条目,该文件可以在您的主目录下的 .ssh 目录中找到。

This is a text file and will show entries for any hostname/ip address/key combinations that have already been added.

这是一个文本文件,将显示已添加的任何主机名/IP 地址/键组合的条目。

So cat ~/.ssh/known_hosts

所以 cat ~/.ssh/known_hosts

should show the following file

应该显示以下文件

You may see something similar to the following

您可能会看到类似于以下内容的内容

removelater.com,123.456.789.10 type-of-key charactersRepresentingTheKeyForRemoveLaterHost keep.com,321.654.987.10 ssh-rsa differentSetOfCharactersRepresentingKeyForKeepHost==

removelater.com,123.456.789.10 type-of-key charactersRepresentingTheKeyForRemoveLaterHost keep.com,321.654.​​987.10 ssh-rsa differentSetOfCharactersRepresentingKeyForKeepHost==

The above file has two lines.

上面的文件有两行。

Using your favorite editor (e.g. vi ~/.ssh/known_hostsor notepad ~/.ssh/known_hosts), simply delete the complete line which has the reference to the host you want to remove and save the file.

使用您喜欢的编辑器(例如vi ~/.ssh/known_hostsnotepad ~/.ssh/known_hosts),只需删除包含对要删除的主机的引用的完整行并保存文件。

Trying to connect again to the host that you have now removed will once more result in

尝试再次连接到您现在已删除的主机将再次导致

The authenticity of host 'removelater.com (123.456.789.10)' can't be established.

无法确定主机“removelater.com (123.456.789.10)”的真实性。

回答by Ewan Mellor

It means that git has used SSH to sign into the remote host for you, and that you had never connected to that server before, and so it added the server to your list of known hosts. If the server ever changes its identity (e.g. your connection is being intercepted by an attacker) then SSH will refuse to connect to it.

这意味着 git 已经使用 SSH 为您登录到远程主机,并且您之前从未连接到该服务器,因此它将服务器添加到您的已知主机列表中。如果服务器改变了它的身份(例如您的连接被攻击者拦截),那么 SSH 将拒绝连接到它。

Read this: https://security.stackexchange.com/questions/20706/what-is-the-difference-between-authorized-key-and-known-host-file-for-ssh

阅读:https: //security.stackexchange.com/questions/20706/what-is-the-difference-between-authorized-key-and-known-host-file-for-ssh

There's no need to worry about this though, unless you are paranoid and expecting someone to try to steal your password or your work.

不过,您无需担心这一点,除非您很偏执并期望有人试图窃取您的密码或您的工作。

回答by Arnab

Following is a quick rewrite I use on Mac for removing a specific host from known_host file:

以下是我在 Mac 上用于从 known_host 文件中删除特定主机的快速重写:

grep -v <full.hostname> ~/.ssh/known_hosts > temp.txt
mv temp.txt ~/.ssh/known_hosts

This basically rewrites everything from the known_hosts files except line(s) that contain(s) the specified hostname.

这基本上重写了 known_hosts 文件中的所有内容,除了包含指定主机名的行。