Git 说“警告:永久添加到已知主机列表中”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9299651/
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-10 12:59:39  来源:igfitidea点击:

Git says "Warning: Permanently added to the list of known hosts"

gitshellcommand-linesshterminal

提问by Donald Taylor

Every time I use git to interact with a remote, such as when pulling or pushing, I am shown the following message:

每次我使用 git 与遥控器交互时,例如拉或推时,都会显示以下消息:

Warning: Permanently added '...' (RSA) to the list of known hosts.

警告:将“...”(RSA)永久添加到已知主机列表中。

How can I prevent this annoying message from displaying? It is only an annoyance—everything functions properly.

如何防止显示这条烦人的消息?这只是一个烦恼 - 一切正常。

回答by Jeremiah Gowdy

Solution: create a ~/.ssh/configfile and insert the line:

解决方案:创建一个~/.ssh/config文件并插入以下行:

UserKnownHostsFile ~/.ssh/known_hosts

You will then see the message the next time you access Github, but after that you'll not see it anymore because the host is added to the known_hostsfile. This fixes the issue, rather than just hiding the log message.

您将在下次访问 Github 时看到该消息,但之后您将不再看到它,因为主机已添加到known_hosts文件中。这解决了问题,而不仅仅是隐藏日志消息。

This problem was bugging me for quite some time. The problem occurs because the OpenSSH client compiled for Windows doesn't check the known_hosts file in ~/.ssh/known_hosts

这个问题困扰了我很长时间。出现问题是因为为 Windows 编译的 OpenSSH 客户端没有检查 known_hosts 文件~/.ssh/known_hosts

ssh -vvvvvvvvvvvvvvvvvvv [email protected]

ssh -vvvvvvvvvvvvvvvvvvv [email protected]

debug3: check_host_in_hostfile: filename /dev/null
debug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hosts
debug3: check_host_in_hostfile: filename /dev/null
debug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hosts
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.

回答by Kyle Kloepper

Add the following line to your ssh config file ($HOME/.ssh/config):

将以下行添加到您的 ssh 配置文件 ($HOME/.ssh/config):

LogLevel=quiet

If running ssh from the command line add the following option to the command string:

如果从命令行运行 ssh,请将以下选项添加到命令字符串中:

-o LogLevel=quiet

For example, the following prints out the gcc version installed on machine.example.org (and no warning):

例如,以下打印出安装在 machine.example.org 上的 gcc 版本(并且没有警告):

ssh -o UserKnownHostsFile=/dev/null \
    -o StrictHostKeyChecking=no \
    -o LogLevel=quiet \
    -i identity_file \
    machine.example.org \
    gcc -dumpversion

回答by user1193229

Set LogLevelto ERROR(not QUIET) in ~/.ssh/configfile to avoid seeing these errors:

在文件中设置LogLevelERROR(not QUIET)~/.ssh/config以避免看到这些错误:

Host *
   StrictHostKeyChecking no
   UserKnownHostsFile /dev/null
   LogLevel ERROR

回答by Jason Carreiro

That message is from SSH, which is warning you that you are connecting to a host which you've never connected to before. I wouldn't recommend turning it off, since it would mean that you might miss a warning about a host key changing, which can indicate a MITM attack on your SSH session.

该消息来自 SSH,它警告您正在连接到以前从未连接过的主机。我不建议关闭它,因为这意味着您可能会错过有关主机密钥更改的警告,这可能表明您的 SSH 会话受到 MITM 攻击。

回答by Stefan Schmidt

To suppress warning messages for sshyou can add the following lines to ~/.ssh/config:

要取消警告消息,ssh您可以将以下行添加到~/.ssh/config

Host *
LogLevel error

That will disable warnings but not error messages. Like the other settings in ~/.ssh/configyou can configure the LogLevelon a per-host basis if you want a more finegrained control.

这将禁用警告,但不会禁用错误消息。与其他设置一样,如果您想要更细粒度的控制,~/.ssh/config您可以LogLevel在每个主机的基础上进行配置。

回答by Larry Cai

It mainly means there are changes for the key for that host ~/.ssh/known_hosts, and it will not automatically UPDATE it. Therefore every time you get this warning message.

这主要意味着该主机的密钥发生了变化~/.ssh/known_hosts,并且不会自动更新它。因此,每次您收到此警告消息时。

This happens often for the connecting to the re-created virtual machines, which changes the key with the same IP address

连接到重新创建的虚拟机时经常发生这种情况,这会更改具有相同 IP 地址的密钥

Solution

解决方案

If you only have one entry, then you can delete the ~/.ssh/known_hostsfile, and after first connection, that the key will be there, and no warning messages after that.

如果您只有一个条目,那么您可以删除该~/.ssh/known_hosts文件,并且在第一次连接后,该密钥将在那里,之后没有警告消息。

If you have multiple entries, then you can use command below to remove

如果你有多个条目,那么你可以使用下面的命令来删除

$ ssh-keygen -R <hostname>

It works fine for me

这对我来说可以

回答by Ricket

If you are using a repository from GitHub, consider using the HTTPSversion of the URL instead, to sidestep this problem entirely:

如果您使用的是来自 GitHub 的存储库,请考虑使用URL的HTTPS版本,以完全避免此问题:

Click the HTTP button and clone that URL instead

单击 HTTP 按钮并克隆该 URL

If you clone your repository from within the Windows GitHub application, this is what it uses for the remote URL. Maybe they know something we don't know.

如果您从 Windows GitHub 应用程序中克隆您的存储库,这就是它用于远程 URL 的内容。也许他们知道一些我们不知道的事情。

回答by Kris Roofe

I have the same question, and I found there is not a .sshfile in my ~. So I just create the .sshdirectory under ~path, and the issue solved.

我有同样的问题,我发现.ssh我的~. 所以我只是.ssh~路径下创建目录,问题就解决了。

回答by Narita

I got into the same issue when I started using a Windows machine. In my case it was because my SSH setup was not done. Github has a very precise documentation on the SSH setup. Once that's taken care, the issue was resolved.

当我开始使用 Windows 机器时,我遇到了同样的问题。就我而言,这是因为我的 SSH 设置没有完成。Github 有关于 SSH 设置的非常精确的文档。一旦解决了这个问题,问题就解决了。

https://help.github.com/articles/checking-for-existing-ssh-keys/https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

https://help.github.com/articles/checking-for-existing-ssh-keys/ https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-到 ssh 代理/

回答by Thanuja

Add ssh key

添加ssh密钥

ssh-keygen -t rsa -b 4096 -C "[email protected]"

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/bitbucket_rsa

crate config file

板条箱配置文件

crate ~/.ssh/config

add below line.

添加下面的行。

UserKnownHostsFile ~/.ssh/known_hosts

Then add pub key and clone your repository... Done.....

然后添加公钥并克隆您的存储库...完成.....