局域网ssh连接等待时间长的解决方法

在自己局域网连接ssh到自己的小主机服务器上的时候发现执行ssh root@192.168.50.176回车之后,在输入密码之前要等好长一段时间,至少需要十几秒钟。

1|01、通过ssh -v root@192.168.50.176查看连接详细信息

# ssh -v root@192.168.50.176 OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 debug1: Connecting to 192.168.50.176 [192.168.50.176] port 22. debug1: Connection established. debug1: identity file C:\\Users\\StaryJie/.ssh/id_rsa type 0 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_ed25519-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_xmss type -1 debug1: key_load_public: No such file or directory debug1: identity file C:\\Users\\StaryJie/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to 192.168.50.176:22 as 'root' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:2ePNJ/cQW7AIsD+veSBc5XS2xy0kmB3W6Dk3uVnBwDQ debug1: Host '192.168.50.176' is known and matches the ECDSA host key. debug1: Found key in C:\\Users\\StaryJie/.ssh/known_hosts:11 debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134217728 blocks debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> debug1: SSH2_MSG_SERVICE_ACCEPT received # 发现代码跑到这里的时候就卡住了 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: publickey debug1: Offering public key: RSA SHA256:Y5wPUy0NUgYMwwSO4juFhw52YyleflOzomjnNvsokXw C:\\Users\\StaryJie/.ssh/id_rsa debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Trying private key: C:\\Users\\StaryJie/.ssh/id_dsa debug1: Trying private key: C:\\Users\\StaryJie/.ssh/id_ecdsa debug1: Trying private key: C:\\Users\\StaryJie/.ssh/id_ed25519 debug1: Trying private key: C:\\Users\\StaryJie/.ssh/id_xmss debug1: Next authentication method: password debug1: read_passphrase: can't open /dev/tty: No such file or directory root@192.168.50.176's password:

2|02、解决方法

2|12.1 修改sshd配置文件

[root@staryjie ~]# egrep -v "^#|^$" /etc/ssh/ssh_config Host * ForwardX11Trusted yes SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE SendEnv XMODIFIERS SAPIAuthentication no UseDNS no [root@staryjie ~]#

2|22.2 添加本地电脑iIP到/etc/hosts

[root@staryjie ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.50.29 windows [root@staryjie ~]#

2|32.3 重启sshd

systemctl restart sshd.service

3|03、查看效果

优化前的速度:

优化之后的速度:


__EOF__

本文作者StaryJie
本文链接https://www.cnblogs.com/jie-fang/p/13430884.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   StaryJie  阅读(1654)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示