無法透過 SSH 存取我的 VPS

無法透過 SSH 存取我的 VPS

我只是錯誤地配置我/etc/passwd在 root 登入時使用了這個命令

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

現在,每當我嘗試透過任何使用者或 root 帳戶存取我的 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 檔案。

相關內容