无法远程 ssh 进入我的家用电脑

无法远程 ssh 进入我的家用电脑

我家里有一台运行 14.04 的电脑。我希望能够从我的笔记本电脑(运行 15.04)向那台电脑(我称之为服务器)发送作业,并在两者之间共享文件。当我的笔记本电脑与服务器连接到同一个路由器时,我能够通过 ssh 进入服务器。但是,当我尝试从不同的网络 ssh 时,我无法进入。我尝试了论坛上人们提供的许多解决方案,但都无济于事。

以下是我迄今为止尝试过的事情的列表:

确保没有防火墙:

sudo iptables -L

显示没有防火墙正在运行。

sudo lsof -i | grep ssh

显示服务器正在监听端口 22。我已进入路由器设置并将端口 22 设置为转发到服务器。使用 canyouseeme.org,我已验证端口 22 在服务器上可见。

我尝试使用 22 以外的端口,方法是将 /etc/ssh/sshd_config(在服务器上)中的设置更改为其他端口,然后运行命令

ssh -p 77 user@server

从我的笔记本电脑。我尝试使用 noip.com 注册服务器,并使用命令

ssh [email protected]

但我收到了错误信息

port 22: Connection timed out.

当我尝试命令时

ssh user@serverpublicIPv6ip

我收到一条错误消息

port 22: Connection refused

当我尝试

ssh user@serverpublicMACip

我收到与 ddns 尝试相同的“连接超时”消息。openssh-client 和 openssh-server 都安装在两台电脑上,并且我已验证,当我尝试运行 ssh 命令时,两台电脑上的 ssh 守护程序都在运行。当我尝试使用 ddns.net 地址进行 ssh 时,我已验证 noip2 进程正在后台运行。我还修改了 /etc/ssh/sshd_config 以包含以下行

GatewayPorts yes

我知道这个问题之前有人问过,但到目前为止,其他帖子上的解决方案都对我没用,我已经把能找到的所有解决方案都读完了。我对 ubuntu 相当熟悉,但对用它联网还是个新手。提前感谢您的回复!

编辑: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
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes no

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

GatewayPorts 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

@JackWasey 我不确定如何回答这个问题。我有一个 Arris“路由器”,它连接到一根同轴电缆,将 Wi-Fi 或以太网馈送到服务器。我在路由器周围使用引号,因为我相信它是一个组合调制解调器/路由器。我已登录我的 ISP 网站并修改了路由器设置以转发端口 22,此外还修改了其他几个端口以尝试将它们用于 ssh。理想情况下,我希望能够使用我通过 noip.com 设置的域,因为我的服务器上的 IP 地址似乎经常更改。

相关内容