I mistakenly entered
chsh -s /usr/bin
chsh -s /bin/bash
and now I can't log into a root shell, how do I start a bash shell as root manually ?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
While root does not have access, a user in the sudo group can still run privileged commands - it seems the error is not in sudo, but elsewhere in the
sudo chshcommand (e.g. chsh error).
As such your sudo is apparently working.
The passwd file can be edited with:
And the root shell changed manually.
(first line of
Fom man vipw
The vipw and vigr commands edits the files /etc/passwd and /etc/group, respectively. With the -s flag, they will edit the shadow versions of those files, /etc/shadow and /etc/gshadow, respectively. The programs will set the appropriate locks to prevent file corruption.
For security reasons, logins whether textual or graphical and utilities like
sudo that allow you to run commands as a different user all run those command through the target user's shell. If the target user's shell is non-functional, well, you've seen the results :-(
Unless you happen to have a still-functional root shell running somewhere or something like a setuid-root binary or something that allows you to bypass this, rebooting and correcting the problem using a rescue system or live image is probably your best bet.
Boot the rescue system, mount your real system's root filesystem somewhere, say,
/mnt/foo, and edit
/mnt/foo/etc/passwd to fix the shell. Save, unmount, and you're done.
init=/bin/bash to your kernel command line ( if booting with grub, press
e to edit the boot entry ), and you will have a bash shell running as root without even having to supply a password. Your root filesystem likely will still be mounted read only though, so you will need to remount it first, then you can change the shell back with