首页 > 系统相关 >Linux ssh远程登录调优

Linux ssh远程登录调优

时间:2024-01-17 15:25:58浏览次数:21  
标签:debug1 file com 调优 ssh key Linux root

背景介绍

公司同事反馈测试环境某台机器ssh登录特别慢,我接到此需求后对该机器上的ssh问题进行处理并对测试环境所有机器进行依次验证ssh速度。

参考文档

SSH调试模式

SSH登录很慢正常情况

欢迎信息

解决思路

按照ssh调优的步骤检查UseDNSGSSAPIAuthentication

如果上述方式调整后仍然很慢则开启debug模式 ssh -vvv进行后续分析

问题原因

由于设置公司机器环境数据,采用A B方式进行脱敏,代替发现问题的机器。

测试环境中A机器是由于:没有关闭UseDNSGSSAPIAuthentication导致登录较慢

测试环境中B机器是由于:设置了ssh登录的欢迎信息,并且欢迎信息中带有机器磁盘、内存、CPU的使用信息导致ssh远程时较慢。

A机器这种情况相对容易解决,具体步骤如下

# 调整ssh的参数,并将其设置为no关闭状态
vim /etc/ssh/sshd_config
UseDNS no
GSSAPIAuthentication no
# 重新启动sshd
systemctl restart  sshd

着重记录下B机器这种情况。

在对测试环境中所有机器进行验证时发现B机器登录极其慢,比A机器这种情况还要慢很多。

登录到B机器后查看UseDNSGSSAPIAuthentication都是关闭状态的,看来问题不在于该参数。

debug过程

我做了一个对比实验,ssh -v debug时找了一台正常的机器C ,得到正常速度的debug信息,然后对比B机器debug信息,查找问题所在。

B机器debug信息

[root@server200 sync]# time ssh root@xxxx -v
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to xxxxx [xxxxx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.11
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.11 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xxxxx: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: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:7sRACE1rYEAUxbJ0HEOLwC+bz4rMzNWZmkUklQOh4hQ
debug1: Host 'xxxx' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:6
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: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to xxx ([xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0

debug1: Remote: /root/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /root/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding



debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-169-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Jan 16 16:11:22 CST 2024

  System load:  2.17                Temperature:             53.0 C
  Usage of /:   28.1% of 111.53GB   Processes:               184
  Memory usage: 7%                  Users logged in:         1
  Swap usage:   0%                  IPv4 address for enp2s0: xxxx

 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
   just raised the bar for easy, resilient and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Expanded Security Maintenance for Applications is not enabled.

1 update can be applied immediately.
To see these additional updates run: apt list --upgradable

23 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

New release '22.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Last login: Tue Jan 16 16:10:46 2024 from 192.168.0.200

C机器的debug信息

[root@server200 sync]# time ssh root@xxxxx -v
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to xxxx [xxx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xxxxx: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: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:o7TNN/TINsGCD1/M9j9ybACmIyTJGt1Xdfyk7RDm6ww
debug1: Host 'xxxxx' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:3
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: 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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to xxxx ([xxxxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0

debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Tue Jan 16 16:09:43 2024 from 192.168.0.180

debug信息的差异

B机器的debug信息比正常机器的debug信息多出如下字段

debug1: Remote: /root/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /root/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding


Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-169-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Jan 16 16:11:22 CST 2024

  System load:  2.17                Temperature:             53.0 C
  Usage of /:   28.1% of 111.53GB   Processes:               184
  Memory usage: 7%                  Users logged in:         1
  Swap usage:   0%                  IPv4 address for enp2s0: xxxxx

 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
   just raised the bar for easy, resilient and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Expanded Security Maintenance for Applications is not enabled.

1 update can be applied immediately.
To see these additional updates run: apt list --upgradable

23 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

New release '22.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

上述信息是在ssh设置的欢迎登录信息,我猜测是因为欢迎登录信息中带有大量需要统计的信息导致变慢的,该信息如下:

  System load:  2.17                Temperature:             53.0 C
  Usage of /:   28.1% of 111.53GB   Processes:               184
  Memory usage: 7%                  Users logged in:         1
  Swap usage:   0%                  IPv4 address for enp2s0: xxxxx

那么关闭ssh的欢迎信息就好了,具体关闭步骤如下

具体步骤

将生成欢迎信息的脚本放到一个bak文件中即可。

root@server206:~# cd /etc/update-motd.d/
root@server206:/etc/update-motd.d# mkdir bak
root@server206:/etc/update-motd.d# mv ./* bak
root@server206:/etc/update-motd.d# ls
bak

设置完毕后重启ssh systemctl restart sshd再次登录验证已经和正常速度一样了。

标签:debug1,file,com,调优,ssh,key,Linux,root
From: https://www.cnblogs.com/liushiya/p/17970072

相关文章

  • 安装ssh出现问题
    问题在安装openssh的时候出现了下面的问题。Creatingconfigfile/etc/ssh/sshd_configwithnewversionCreatingSSH2RSAkey;thismaytakesometime...OpenSSLversionmismatch.Builtagainst30000020,youhave30100000解决方法清除所有的安装内容sudoapt-g......
  • 每天一个linux命令(47):iostat命令
      Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视。它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况。同vmstat一样,iostat也有一个弱点,就是它不能对某个进程进行深入分析,仅对系统的整体情况进行分析。iost......
  • SUSE Linux Enterprise Server 12 SP5 配置静态IP
    背景介绍近期看到的一道面试题,要求使用Suse系统。由于我之前没有接触过Suse系统,记录下如何配置IP地址。(环境是VMwareFusion虚拟机)参考文档SuSE12SP5配置静态IP地址-魔幻小生-博客园(cnblogs.com)具体步骤查看系统版本linux-nvlm:/etc/sysconfig/network#hostnamec......
  • Linux 中 Crontab 执行时的环境变量问题(allure命令不执行)
    前几天做了UI自动化脚本部署linux服务器,但是放下脚本的allure命令不执行(生成allure报告和启动allure服务的命令不执行),然后就各种找问题,一开始怀疑是allure的环境变量问题,但是发现使用allure--version可以正常显示allure的版本没问题后边尝试将环境变量加入linuxcronta......
  • RaspberryPi(树莓派)安装操作系统时默认启用 SSH
    如果对RaspberryPi(树莓派)安装操作系统的时候不做任何修改的话默认是不用SSH的。单击编辑设置。配置SSH在当前的界面中,选择启用SSH。  那么在安装完成RaspberryPi(树莓派)后的SSH是自动启动服务的。 ......
  • Windows下的Linux子系统(WSL)
    什么是WSLWSL:WindowssubsystemforLinux,是用于Windows上的Linux的子系统作用很简单,可以在Windows系统中获取Linux系统环境,并完全直连计算机硬件,无需通过虚拟机虚拟硬件,不会影响Windows系统本身为什么使用WSLWSL作为自Windows10以来的全新特性正逐步颠覆开发人员的选择传......
  • Linux系统安装Jmeter
     今天我们学习下如何在Linux下安装Jmeter,因为Jmeter是Java开发的,需要依赖JDK环境,因此我们需提前安装好JDK。本人环境:CentOS7.364位JDK1.8(可参考文章:Linux下安装JDK1.8)下载Jmeter安装包Jmeter是开源的工具,我们直接到官网下载即可,本次安装的版本是 5.6.3。最新版本......
  • linux之线程概念(八千字长文详解)
    linux之线程概念线程的概念首先我们要进程和线程区分开来什么是进程——专业点的说法就是加载到内存的一个执行流!而在linux里面本质点的来说就是内核数据结构+进程对应的代码和数据每一个进程——都有自己独立的PCB,自己的进程地址空间,页表进程地址空间决定了,进程能够看到的......
  • 远程登录Linux服务器工具MobaXterm_Personal使用说明
    1、下载MobaXterm_Personal_21.5安装包(https://files.cnblogs.com/files/blogs/667041/MobaXterm_Personal_21.5.rar?t=1705457459&download=true),双击运行MobaXterm_Personal_21.5.exe2、点击3、点击4、输入remotehost,Port默认22,点击OK5、输入服务器登录的用户名和密码......
  • 知识汇总:查看linux服务器系统命令
    要查看Linux服务器的系统信息,你可以使用多种命令来获取不同类型的信息。以下是一些常用的命令和它们的用途:uname -显示基本的系统信息uname-a:显示所有的系统信息,包括内核名称、主机名、内核发行版本、内核版本、机器类型、处理器类型、硬件平台和操作系统。hostnamectl......