I mistakenly entered
chsh -s /usr/bin
instead of
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 communityWhile 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 chsh
command (e.g. chsh error).
As such your sudo is apparently working.
The passwd file can be edited with:
sudo vipw
And the root shell changed manually.
(first line of /etc/passwd
usually)
root:x:0:0:root:/root:/bin/bash
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.
vipw
and vigr
, thank you! I always used sudo vim /etc/passwd
visudo
sudo.ws/man/1.8.15/visudo.man.html too, @tac
Mar 28, 2016 at 16:05
Another option, assuming you have access to another account, is to manually override the default shell by using su --shell=/bin/bash
:
-s, --shell=SHELL
run SHELL if /etc/shells allows it
The primary advantage of this is that it only requires access to another account, not another privileged one.
For security reasons, logins whether textual or graphical and utilities like su
and 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.
/etc/passwd
is not plaintext? I haven't seen that in at least, like, a decade. Is that still a thing on some systems? Anyway, I guess chroot /mnt/foo chsh -s /bin/bash
might do the trick in that case?
Add 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 chsh
.
sudo usermod -s /bin/bash jdoe
will change the shell of jdoe to bash
. You can then sudo egrep jdoe /etc/passwd
to verify.
sudo vipw
work?