无法通过 SSH 访问我的 VPS

无法通过 SSH 访问我的 VPS

我只是配置错误,/etc/passwd在 root 登录时使用了此命令

root@ubuntu:~# sh -c 'echo "nope no entry mates" > /etc/passwd'

现在,每当我尝试通过任何用户或根帐户访问我的 VPS 时,我都会得到

ssh root@myVpsIp
kex_exchange_identification: read: Connection reset

SSH 调试

C:\Users\tommy>ssh root@myVpsIp -v    
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Connecting to myVpsIp [myVpsIp] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\tommy/.ssh/id_rsa type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\tommy/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
kex_exchange_identification: Connection closed by remote host

仍然有一个已登录的 root ssh 窗口,我在其中尝试找到问题解决方案并找到了问题

root@ubuntu:~# cut -d : -f 1 /etc/passwd
nope no entry mates

有人知道如何恢复我的/etc/passwd吗?

答案1

查看 /var/backups/passwd.bak 中是否有 /etc/passwd 的备份,如果已运行cp /var/backups/passwd.bak /etc/passwd,则运行chmod 644 /etc/passwd

如果你没有 /var/backups/passwd.bak,你可以使用 /etc/passwd-

看起来您已经通过运行的第一个命令删除了整个 /etc/passwd 文件。

相关内容