linux - ssh相关配置

这篇博客介绍了如何处理SSH连接时遇到的kexprotocolerror问题。通过检查和更新`/etc/ssh/sshd_config`文件,添加特定的KexAlgorithms设置并重启SSH服务,可以解决这个问题。此外,还展示了配置文件的内容和相关日志信息。

开启ssh

sudo service ssh start

开机打开ssh

sudo systemctl enable ssh

查看ssh状态

sudo systemctl status sshd
kylin@kylin-greatwall:~$ sudo systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: e>
     Active: active (running) since Tue 2022-08-16 15:06:30 CST; 3min 55s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 6519 (sshd)
      Tasks: 1 (limit: 9249)
     Memory: 3.6M
     CGroup: /system.slice/ssh.service
             └─6519 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

816 15:06:30 kylin-greatwall systemd[1]: Started OpenBSD Secure Shell server.
816 15:06:44 kylin-greatwall sshd[6533]: error: kex protocol error: type 30 >
816 15:06:44 kylin-greatwall sshd[6533]: error: Received disconnect from 172>
816 15:06:44 kylin-greatwall sshd[6533]: Disconnected from 172.29.157.116 po>
816 15:07:09 kylin-greatwall sshd[6539]: error: kex protocol error: type 30 >
816 15:07:09 kylin-greatwall sshd[6539]: error: Received disconnect from 172>
816 15:07:09 kylin-greatwall sshd[6539]: Disconnected from 172.29.157.116 po>
816 15:08:51 kylin-greatwall sshd[6723]: error: kex protocol error: type 30 >
816 15:08:51 kylin-greatwall sshd[6723]: error: Received disconnect from 172>
816 15:08:51 kylin-greatwall sshd[6723]: Disconnected from 172.29.157.116 po>
lines 1-21/21 (END)...skipping...
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-08-16 15:06:30 CST; 3min 55s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 6519 (sshd)
      Tasks: 1 (limit: 9249)
     Memory: 3.6M
     CGroup: /system.slice/ssh.service
             └─6519 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startup

出现 error: kex protocol error时

在这里插入图片描述

在文件/etc/ssh/sshd_config添加如下,然后重启ssh:

KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1
LoginGraceTime 120m
PermitRootLogin yes
StrictModes yes

/etc/ssh/sshd_config

kylin@kylin-greatwall:~/zz_team/linbo$ cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

LoginGraceTime 120m
PermitRootLogin yes
StrictModes yes

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值