ssh: 호스트 포트 22에 연결: 외부 IP 주소로 연결이 거부되었습니다.

ssh: 호스트 포트 22에 연결: 외부 IP 주소로 연결이 거부되었습니다.
ssh: connect to host XXX.XXX.XXX.XX port 22: Connection refused

외부 IP(WAN IP 주소)로 연결을 시도할 때 이런 현상이 발생합니다.

LAN에서 내부 IP 주소를 사용하여 성공적으로 연결할 수 있습니다.

외부 IP로 연결할 수 없는 이유는 무엇입니까?

라우터에서 포트 22의 SSH에 대한 내부 IP 주소로 포트 전달을 수행했습니다.

내가 달릴 때ps -eaf|grep sshd

루트 5942 1 0 18:42 ? 00:00:00 /usr/sbin/sshd
1000 6628 6382 0 18:55pts/0 00:00:00 grep sshd

SSH -VV를 실행할 때[이메일 보호됨]

OpenSSH_6.0p1 Debian-4, OpenSSL 1.0.1e 2013년 2월 11일

내 sshd_config 파일:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0

Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

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

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

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

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

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

Subsystem sftp /usr/lib/openssh/sftp-server

# 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

답변1

라우터에서 올바른 작업을 하였습니까?(예: 이미 다른 서비스의 다른 포트에서 작동합니까?)

"연결 거부"가 TCP 수준에서 발생하기 때문에 묻는 것입니다. 그 이유는 일반적으로 대상 컴퓨터의 해당 포트를 수신 대기하는 사람이 없거나(sshd가 실행되지 않는 것과 동일함) 일부 방화벽이 이를 차단하기 때문입니다.

로컬 네트워크의 주소와 작동한다고 말씀하셨기 때문에 전달을 수행하지 않거나 다른 것으로 전달하지 않는 라우터인 것처럼 보입니다.

답변2

아래와 같이 SSH 사용자 구성 파일에 다음 줄을 추가합니다.

vi ~/.ssh/config

Host *
ServerAliveInterval 300

아래와 같이 권한을 변경합니다.

 chmod 600 ~/.ssh/config

데몬을 다시 시작하십시오. 도움이 되었기를 바랍니다.

관련 정보