
그래서 집에서 SSH 서버에 접속할 수 있도록 노력했고, 인터넷에서 접속할 수 있도록 SSH 포트를 열었습니다. LAN IP 주소를 통해 로그인하면 모든 것이 완벽하게 진행됩니다. 그런데 공인 IP 주소로 로그인하면 잠시 연결을 수락했다가 바로 연결이 끊어집니다. 이 네트워크에는 방화벽 규칙이 활성화되어 있지 않습니다. 내 쪽에서 본 모습은 다음과 같습니다. 모든 사용자 이름을 user로 바꾸고 모든 IP를 1.1.1.1로 바꿨습니다.
user@user:~/Desktop$ ssh -p 443 [email protected] -vvv
OpenSSH_7.9p1 Ubuntu-10, OpenSSL 1.1.1b 26 Feb 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolve_canonicalize: hostname 1.1.1.1 is address
debug2: ssh_connect_direct
debug1: Connecting to 1.1.1.1 [1.1.1.1] port 443.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type -1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: identity file /home/user/.ssh/id_xmss type -1
debug1: identity file /home/user/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Ubuntu-10
ssh_exchange_identification: Connection closed by remote host
SSH 서버의 auth.log에 있는 오류는 다음과 같습니다.
Aug 14 23:36:46 user sshd[2761]: Server listening on 0.0.0.0 port 443.
Aug 14 23:36:46 user sshd[2761]: Server listening on :: port 443.
Aug 14 23:36:46 user sudo: pam_unix(sudo:session): session closed for user root
Aug 14 23:36:58 user sshd[2762]: Connection closed by authenticating user user 1.1.1.1 port 41122 [preauth]
Aug 14 23:40:42 user sshd[2790]: Accepted password for user from 1.1.1.1 port 41376 ssh2
SSH 서버의 /etc/ssh/sshd_config는 다음과 같습니다.
# 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 443
#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 no
MaxAuthTries 69900
MaxSessions 10932
#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 no
#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 30000
#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
그리고 마지막으로 내 /etc/hosts.allow는 다음과 같습니다.
# /etc/hosts.allow: list of hosts that are allowed to access the system.
# See the manual pages hosts_access(5) and hosts_options(5).
#
# Example: ALL: LOCAL @some_netgroup
# ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
#
# If you're going to protect the portmapper use the name "rpcbind" for the
# daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
#
sshd: ALL
답변1
클라이언트는 SSH "인사말" 메시지를 보낸 후 서버가 즉시 연결을 종료한다고 말합니다.
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Ubuntu-10
ssh_exchange_identification: Connection closed by remote host
그리고 귀하의 서버는 다음과 같이 말합니다.고객연결을 종료하는 중입니다:
sshd[2762]: Connection closed by authenticating user user 1.1.1.1 port 41122 [preauth]
그것은 거의 항상 무언가를 의미합니다.중간에연결이 닫힌 것처럼 보이도록 가짜 TCP RST를 보내고 있습니다. 포트 443(일반적으로 HTTPS/TLS 포트)에 연결하고 연결 끊김은 TLS가 아닌 일부 데이터가 전송된 후에만 발생하므로 서버의 ISP나 클라이언트의 ISP가 HTTPS 연결을 가로채고 있다고 결론을 내릴 수 있습니다.
(이는 예상치 못한 데이터 형식을 침입으로 처리할 수 있는 면밀히 감독되는 기업 네트워크에서 연결하거나 고객이 웹사이트를 탐색하는 것 외에는 아무 것도 하지 않기를 바라는 제한된 공용 Wi-Fi에서 연결할 때 발생할 가능성이 높습니다.)
SSH가 있을 것으로 예상되는 포트 22를 사용해 보십시오.
포트 443이 유일한 옵션인 경우 다음을 시도해 볼 수 있습니다.충격을 주다또는 TLS 내부에 임의의 TCP 기반 연결을 넣어 HTTPS 연결과 매우 유사하게 보이게 하는 유사한 프로그램입니다. (이것은 내부에서 HTTP인 척하지 않으므로 네트워크가 실제로 TLS 데이터를 해독하는 경우 작동하지 않지만 외부 계층만 보는 방화벽을 속일 것입니다.)
회사 네트워크나 대학 네트워크에 문제가 있는 경우 관리자가 필터링을 우회하는 것보다 SSH 액세스를 허용하도록 하는 것이 더 쉽고 덜 위험할 수 있습니다.