Let's say I've gone and done a silly thing, such as using 'chsh' to change the root user's shell to a bad file path. Future logins to the root account will abruptly fail, citing /bin/whatever not being found, and boot you back out to the login screen. Barring a recovery mode or inserting a LiveCD to edit /etc/passwd, what are my options for getting my system back? Let's also assume (for fun?) that there are no other users in wheel. Thoughts?
Shell – Recovering from setting root’s shell to a bad file
loginshellusers
Best Answer
When booting, append
init=/bin/bash
(or a path to any other functional shell) to your boot options - you will be dropped straight to a single user shell. You might need to domount -o remount,rw /
before modifying the/etc/passwd
entry in that environment. After that, just reboot or doexec /sbin/init 3
. Just do not typeexit
or press Ctrl+D, as these would result in kernel panic*.One additional variation of this method might be necessary on some systems loaded in two-stage mode (with an initrd image). If you notice that the boot options contain
init=
and, most importantly,real_init=
, then the place to put/bin/bash
should be the latter parameter (i.e.real_init=/bin/bash
).* This is because in that environment, the shell is seen by the kernel as the init program - which is the only process that kernel knows - it represents a running system underneath to the kernel's eye. Suddenly ending that process, without telling the kernel to shutdown the system, must result in kernel panic. (Wouldn't you panic if suddenly everything around you went black and silent?)