[SOLVED] Accidental "chsh" type, now locked out of
I have a big dilemma on my hands, and am on my last straw trying to solve this. While typing too fast and wanting to change the shell for a given user to prevent SSH access, I ran the following command:
sudo chsh /sbin/nologin
Without specifying the user, it seemed as though it defaulted to making the root shell /sbin/nologin, not good!
I booted into recovery mode, and followed these steps:
* mounted /dev/xvda /media/xvda
edited /etc/passwd to change root shell back to /bin/bash
Checked file again, shell set to bin bash
Added user "onestp" to sudoers list as a fallback
ran sudo usermod -s /bin/bash root and was no change, so shell was correct
changed root password to be sure
Exited & rebooted</list>
Now when I SSH in as root I still have no acccess. When I SSH in as user onestp (with sudo ability) and run this command:
sudo su -s /bin/bash root
But when typing in password I still get the error that /sbin/nolong does not exists, so the shell is not changing for user root.
Any ideas on how I can recover access to my VPS as root user?
Thank you,
Simon
4 Replies
Don't really know what's going on there, though. Does it actually now say that "/sbin/nolong" doesn't exist even though you changed root's shell to "/sbin/nologin"?
Yes it says that it does not exist, even though I set the shell for the user (root in this case).
I booted into recovery, added user onestp to the sudoers list, but now it still says that user onestp is not in the sudoers list.
Something seems so wrong here. I am booting into recovery again, attempting to add the user to the sudoers list. While I am at it I will also change the user onestp's shell to /bash/bin in the hope that I can further fix this issue.
Will let you know what the outcome is. Thank you
Regards,
Simon
When logging into the recovery console, I had to mount the /dev/xvda to /media/xvda
HOWEVER, when I was running my commands such as sudo nano /etc/passwd, they were running relative to the RECOVERY IMAGE root and NOT my mounted location.
So, while in the location /media/xvda I ran sudo nano etc/passwd and changed the shell back to /bin/bash for root.
All is well now, and SSH access as root has been restored.
I hope this saves someone hours of trouble some day.