Can I set zsh as default shell while being logged in as root? I did
chsh -s /bin/zsh and used my root password for authentication, but failed.
A trick is to set interactive root shells to use zsh and leave non-interactive shells to continue to use /bin/sh.
This can still lead to "expectation" problems as described in other responses but at least you will not blow up any non-interactive processes.
Add the following to the end of /root/.bashrc
if [ ! -z "$PS1" ]; then exec /bin/zsh $* fi
In general it is a bad idea to change the root shell away from /bin/sh. It is better to add another account, e.g. zroot, that still has a UID of 0 but has zsh as a shell. However to attempt to answer the question, if you are logging in as root, then you don't need to use
sudo. Just use
chsh -s /bin/zsh root
and give the
root password in response to the request from chsh. Worth specifing the 'root' explicitly.
If you are logging in as 'fred', then use
sudo su root
and answer the password request with
fred's password. This should give you a root shell. Proceed as if you had originally logged in as root.
Make sure the /bin/zsh is listed in /etc/shells.
Editing passwd file with normal editor is not recommended to do this use
and change shell to zsh,honestly i don't understand why you want to change the root shell,root account must used only for administration thing,for normal work use unprivileged user. After this try to log in on other tty whitout(is important) disconnect from current tty,if works you can see your new shell. If you want to use immediately zsh,simply type zsh. Conclusion
I want to use my new shell now = type zsh I want to use my new shell + change = chsh -s or vipw
p.s= if your zsh is not installed on those path(/bin /sbin..) and you have to do a single user login with root,will not work because cannot find your shell,this can happen also on system with /usr separated from root/mounted on other lvm or partition