尝试通过 ssh 远程连接到 lubuntu 服务器时,连接被拒绝

尝试通过 ssh 远程连接到 lubuntu 服务器时,连接被拒绝

我尝试远程 ssh 到我的 Lubuntu SSH 服务器时超时。我尝试在我的 wifi 路由器上启用端口转发。作为故障排除的一部分(以及为了安全起见),我将 sshd_config 文件 # 端口条目从 22 更改为 1022。LAN 连接始终有效(同一个 wifi 路由器)。

令人惊奇的是,即使 SSH 客户端仍在使用端口 22,LAN 连接仍然有效。我对此感到惊讶,因为 SSHD_Config 文件现在是端口 1022。

对此有什么想法吗?以及如何解决远程连接问题?

谢谢

根据 Robert Reidl 的评论,编辑问题以包含 sshd_config

#   $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm 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.

#Port 1022
#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 prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#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
#UseLogin no
#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

附加信息:

port fwd config in 
router: ext: 0.0.0.0 1022 / 1022 
int: 192.168.0.17 1022 / 1022 22 
udp/tcp:    Both enabled:   Yes


UFW config 

To                         Action      From
--                         ------      ----
1022                       ALLOW IN    Anywhere
22/tcp                     ALLOW IN    Anywhere
1022 (v6)                  ALLOW IN    Anywhere (v6)
22/tcp (v6)                ALLOW IN    Anywhere (v6)

答案1

删除您想要更改的任何其他行#前面的和前面的,然后重新启动。Port 1022sshd

这将注释掉每一行,意味着不会使用您所做的更改,而是使用默认设置。

答案2

此外,当通过防火墙/路由器打开端口时,您可以将目标端口设为 22。因此源端口 1022 目标端口 22。这样,您可以在本地网络上使用默认端口 22 进行操作,而不必更改设置等。但是,当从 wan 连接时,您将使用端口 1022,路由器会将其转换为端口 22,以转换为网络上机器的 IP 地址。在您的示例中,路由器分机:0.0.0.0 1022 / 1022 int:192.168.0.17 22 / 22 udp/tcp:均已启用:是

只需确保在 /etc/ssh/sshd_config 上将其改回 22

答案3

哈哈关闭 UFW 和路由器防火墙后,我可以从远程位置进行 ssh。将路由器防火墙调至“低”后,我仍然可以从远程位置进行 ssh。防火墙的中高设置显然会阻止 ssh 远程转发。非常有趣。顺便说一下,路由器是 ARRIS SBG6782-AC。谢谢大家

相关内容