如何重新获得远程服务器的 ssh 访问权限

如何重新获得远程服务器的 ssh 访问权限

我使用 VirtualBox 上的 Linux 终端在我的网站上工作,并且能够安全地访问远程服务器而无需密码验证。我只需输入“ssh {sudo user}@{IP}”。管道中断后,我失去了重新连接的能力。

我认为这是一个与防火墙相关的问题,于是我重新执行了我的步骤(这很容易,因为我遵循了本教程):https://www.youtube.com/watch?v=goToXTC96Co&t=318s)。这样做之后,我发现在启用 ssh 访问之前我已经允许了它,所以我不认为这是防火墙造成的。

在认为这是与密钥相关的问题后,我生成了一个新的密钥对(意外覆盖了旧密钥对),并尝试将生成的公钥安全地复制到服务器,但无法正常工作。通过覆盖服务器上公钥的私钥,我可能搞砸了自己,但作为新手,可能还有其他我不知道的解决方案。T这是我现在得到的输出(带有调试信息):

root@john-VirtualBox:/home/john# ssh [email protected] -v


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 xxx.xxx.xx.xxx [xxx.xxx.xx.xxx] port 22.
 - debug1: Connection established.
 - debug1: permanently_set_uid: 0/0
 - debug1: identity file /root/.ssh/id_rsa type 0
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_rsa-cert type -1
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_dsa type -1
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_dsa-cert type -1
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_ecdsa type -1
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_ecdsa-cert type -1
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_ed25519 type -1
 - debug1: key_load_public: No such file or directory
 - debug1: identity file /root/.ssh/id_ed25519-cert type -1
 - debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
 - debug1: Remote protocol version 2.0, remote software version
   OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
 - debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat
   0x04000000
 - debug1: Authenticating to xxx.xxx.xx.xxx:22 as 'jw'
 - debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received
 - debug1: kex: algorithm: curve25519-sha256
 - debug1: kex: host key
 - algorithm: rsa-sha2-512
 - debug1: kex: server->client cipher:[email protected] MAC
   <implicit> compression: none
 - debug1: kex: client->server cipher: [email protected]
   MAC: <implicit> compression: none
 - debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
 - debug1: Server host key: ssh-rsa SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 - debug1: Host 'xxx.xxx.xx.xxx' is known and matches the RSA host key.
 - debug1: Found key in /root/.ssh/known_hosts:4
 - debug1: rekey after 134217728 blocks
 - debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS
 - debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134217728 blocks 
 - debug1: SSH2_MSG_EXT_INFO received
 - debug1:
   kex_input_ext_info:server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
 - debug1: SSH2_MSG_SERVICE_ACCEPT received
 - debug1: Authentications that can continue: publickey
 - debug1: Next authentication method: publickey
 - debug1: Offering public key: RSA   
   SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx /root/.ssh/id_rsa
 - debug1: Authentications that can continue: publickey
 - debug1: Trying private key: /root/.ssh/id_dsa
 - debug1: Trying private key: /root/.ssh/id_ecdsa
 - debug1: Trying private key: /root/.ssh/id_ed25519
 - debug1: No more authentication methods to try.

这是我收到的错误输出(没有调试信息):

[email protected]: Permission denied (publickey)

/etc/ssh/sshd_config 在问题发生之前更改了设置:

  • PermitRootLogin no(防止黑客获取 root 访问权限)
  • PasswordAuthentication no(这样我就不用每次都输入密码就可以使用 ssh)

相关内容