Can't access my VPS through SSH
I just misconfigured my /etc/passwd
had used this command on root login
root@ubuntu:~# sh -c 'echo "nope no entry mates" > /etc/passwd'
Now whenever I try to access my VPS though any user, or root account, I get
ssh root@myVpsIp
kex_exchange_identification: read: Connection reset
SSH Debug
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
There is still a logged in root ssh window in which I tried to find the problem solution and got to the issue
root@ubuntu:~# cut -d : -f 1 /etc/passwd
nope no entry mates
Anybody know how to restore my /etc/passwd
?
Solution 1:
See if you have backup of /etc/passwd located in /var/backups/passwd.bak and if you have run cp /var/backups/passwd.bak /etc/passwd
and then run chmod 644 /etc/passwd
If you don't have /var/backups/passwd.bak, you can use /etc/passwd-
It seems you have deleted your entire /etc/passwd file with the first command that you've run.