我得到了一些服务器空间并安装了一个带有防火墙的 apache Web 服务器本教程但现在当我尝试 ssh 到服务器时出现此错误
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to xx.xxx.xxx.xx [xx.xxx.xxx.xx] port 80.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: ssh_exchange_identification: HTTP/1.1 400 Bad Request
debug1: ssh_exchange_identification: Date: Tue, 02 Jul 2019 19:27:18 GMT
debug1: ssh_exchange_identification: Server: Apache/2.4.18 (Ubuntu)
debug1: ssh_exchange_identification: Content-Length: 313
debug1: ssh_exchange_identification: Connection: close
debug1: ssh_exchange_identification: Content-Type: text/html; charset=iso-8859-1
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
debug1: ssh_exchange_identification: <html><head>
debug1: ssh_exchange_identification: <title>400 Bad Request</title>
debug1: ssh_exchange_identification: </head><body>
debug1: ssh_exchange_identification: <h1>Bad Request</h1>
debug1: ssh_exchange_identification: <p>Your browser sent a request that this server could not understand.<br />
debug1: ssh_exchange_identification: </p>
debug1: ssh_exchange_identification: <hr>
debug1: ssh_exchange_identification: <address>Apache/2.4.18 (Ubuntu) Server at sample.com Port 80</address>
debug1: ssh_exchange_identification: </body></html>
ssh_exchange_identification: Connection closed by remote host
我尝试使用 vim scp 查看 ssh_config 和 sshd_config 文件,但我得到的都是空文件。我目前无法访问服务器。我不知道 key_load_public 文件是什么或者它应该是什么样子。服务器没有访问密钥,只有一个用户名和密码。
答案1
根据评论,您似乎必须在服务器上打开端口 22。就像 @GracefulRestart 所说,端口 22 是 SSH 的默认端口。当您尝试使用服务器上的端口 80 启动 SSH 会话时,您实际上是在连接到 Apache 服务器,而不是 SSH 服务器。我们知道您正在与 Web 服务器对话,因为它实际上响应了 404 错误页面的 HTML。
要打开端口 22,您可以按照您引用的教程中的步骤 2 进行操作,但将应用程序更改为 OpenSSH 而不是 Apache。然后尝试再次启动 SSH 会话(在端口 22 上)进行确认。
注意:如果您打算在公共互联网上使用 SSH 服务器一段时间,您可能需要考虑使用非标准 SSH 端口。如果您使用端口 22,则将要查看登录尝试。还可以考虑通过 SSH 禁用 root 登录,并确保您的密码符合要求。