这是我的问题:
我想通过ssh从macbookpro(10.10.4)登录到我的ubuntu服务器,但无法从任何公共IP地址运行
当我使用与服务器相同的wifi并尝试连接到专用/本地IP时,它工作正常。询问我的密码,我可以登录:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to XXX.XXX.X.XX [XXX.XXX.X.XX] port 22.
debug1: Connection established.
debug1: identity file /Users/XXXXX/.ssh/id_rsa type -1
debug1: identity file /Users/XXXXX/.ssh/id_rsa-cert type -1
debug1: identity file /Users/XXXXX/.ssh/id_dsa type -1
debug1: identity file /Users/XXXXX/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<2048<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA XX:XX:XX:XXX:XX:XX
debug1: Host 'XXX.XXX.X.XX' is known and matches the RSA host key.
debug1: Found key in /Users/XXXXX/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/XXXXX/.ssh/id_rsa
debug1: Trying private key: /Users/XXXXX/.ssh/id_dsa
debug1: Next authentication method: password
[email protected]'s password:
但是,当我尝试从公共IP连接时,会收到以下消息:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to XX.XX.XXX.XX [XX.XX.XXX.XX] port 22.
debug1: connect to address XX.XX.XX.XX port 22: Connection refused
ssh: connect to host XX.XX.XX.XX port 22: Connection refused
到目前为止,这是我所做的:
检查哪个端口正在监听ssh->端口22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5886/sshd
检查防火墙是否在端口22上处于活动状态->它不是
sudo ufw verbose
Status: inactive
试图使用apt-get卸载/重新安装openssh-server->并没有改变
尖叫并在墙上打孔->没有改变任何事情
我该怎么做才能解决此问题?
从Mac连接是否存在特定问题?
我对Linux很陌生,所以请保持柔和:)
首先:欢迎光临!
从日志和错误消息中可以看到,路由器上未启用端口转发,以允许通过SSH连接到计算机。
这可以通过查找路由器模型并弄清楚如何将端口22转发到服务器的IP地址来完成。您可以使用确定服务器的IP地址ifconfig
。在路由器设置中,您也可以为服务器设置一个静态IP地址,这样它就不会四处移动。
另一个IP地址问题是,如果您的ISP不使用动态IP,则您的IP地址可能会“随机更改,恕不另行通知”。这取决于您的ISP,我的ISP“使用”动态IP,但是在我住这里的8个月中,它没有变化。
您可以设置脚本,让服务器在需要访问时每天通过电子邮件向您发送外部IP地址。
如果您继续遇到连接被拒绝的错误,则您的ISP可能还出于“安全性”而在其他端口列表中阻止了端口22。
这是一个巨大的警告,而我所说的是巨人警告。此过程将使您的服务器容易受到打开该端口的任何形式的攻击。您将要尽自己最大的能力来增强服务器抵抗此类攻击的能力。可以通过多种方法完成此操作,建议遵循所有方法。
如何保护Ubuntu 16.04 LTS服务器安全是深入保护服务器安全的良好指南。
请确保您实施尽可能多的方法。我强烈建议您使用密钥访问,锁定特定用户并禁用root用户访问权限等。如果您绝对不需要外部IP的访问,那么我就不会打扰。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句