每次我使用git与遥控器交互时,比如拉或推时,我都会看到以下消息:
警告:永久添加'…' (RSA)到已知主机列表。
如何防止显示这个烦人的消息?这只是一个烦恼——一切都很正常。
每次我使用git与遥控器交互时,比如拉或推时,我都会看到以下消息:
警告:永久添加'…' (RSA)到已知主机列表。
如何防止显示这个烦人的消息?这只是一个烦恼——一切都很正常。
当前回答
当我开始使用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/
其他回答
在我的例子中,这是因为设置服务器的管理员在~/.ssh/config中设置了这些选项
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
在大多数情况下,不使用~/。ssh / known_hosts文件中。但是对于企业gitlab回购,每当它给出“警告:永久添加…”到已知的宿主名单。”
我的解决方案是注释掉UserKnownHostsFile /dev/null行,这允许创建~/.ssh/known_hosts。在那之后,它没有再给出任何警告。
在known_hosts中也可能有旧的/无效的条目。
# find entry in ~/.ssh/known_hosts
ssh-keygen -F <hostname>
# delete entry in ~/.ssh/known_hosts
ssh-keygen -R <hostname>
创建一个~/。Ssh /config文件并插入行:
UserKnownHostsFile ~/.ssh/known_hosts
然后,您将在下次访问Github时看到该消息,但在此之后,您将不再看到它,因为主机已添加到known_hosts文件。这可以修复问题,而不仅仅是隐藏日志消息。
这个问题困扰了我很长时间。出现此问题是因为为Windows编译的OpenSSH客户端没有检查~/.ssh/known_hosts中的known_hosts文件
SSH -vvv git@github.com
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.
在ssh配置文件($HOME/.ssh/config)中添加以下行:
LogLevel=quiet
如果从命令行运行ssh,在命令字符串中添加以下选项:
-o LogLevel=quiet
例如,下面打印在machine.example.org上安装的gcc版本(没有警告):
ssh -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-o LogLevel=quiet \
-i identity_file \
machine.example.org \
gcc -dumpversion
您只需要这个命令。
如果是,使用GitHub:
ssh -T git@gitlab.com
如果你使用GitLab:
ssh -T git@gitlab.com
我在Linux/Cent操作系统虚拟机中也遇到过同样的错误,这是因为重启后IP发生了变化。为了解决这个问题,我在网络中定义了一个静态IP,并将该条目添加到/etc/hosts文件中。对于静态IP,请提到稍微高一些的范围值。例如,如果您当前的IP (ipconfig/ifconfig)是192.168.0.102,下次重启后可能会变成192.168.0.103。因此,在IPV4设置中定义您的静态IP为192.168.0.181,这应该可以做到这一点。