web-dev-qa-db-ja.com

外部IPからのSSHに関する問題

そこで、自宅からアクセス可能な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
mama moss

クライアントは、SSHの「挨拶」メッセージを送信した直後にサーバーが接続を終了していると言います。

debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Ubuntu-10
ssh_exchange_identification: Connection closed by remote Host

そして、サーバーはclientが接続を終了していると言います:

sshd[2762]: Connection closed by authenticating user user 1.1.1.1 port 41122 [preauth]

これはほとんどの場合、途中の何かが偽のTCP RSTを送信して、接続が閉じられたように見せていることを意味します。ポート443(通常はHTTPS/TLSポート)に接続していて、一部の非TLSデータが送信された後にのみ切断が発生するため、サーバーのISPまたはクライアントのISPのいずれかがHTTPS接続を傍受しているというのが妥当な結論です。

(これは、予期しないデータ形式を侵入として扱う可能性のある厳重に監視された企業ネットワークから、または顧客にWebサイトの閲覧以外のことをさせたくない限られたパブリックWi-Fiから接続する場合に発生する可能性があります。)

SSHが必要なポート22を使用してみてください。

ポート443が唯一のオプションである場合は、 stunnel または同様のプログラムを試してみてください。これにより、TLS内に任意のTCPベースの接続が配置され、HTTPS接続のように見えます。 (これは内部がHTTPのふりをしていないため、ネットワークが実際にTLSデータを復号化している場合は機能しませんが、外部層のみを監視するファイアウォールをだまします。)

会社のネットワークまたは大学のネットワークに問題がある場合は、フィルタリングをバイパスするよりも、管理者にSSHアクセスを許可させる方が簡単(かつリスクが少ない)になる可能性があります。

1
user1686