2

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.

4
  • You want to set your user or root shell to zsh?
    – a0f3dd13
    Oct 23 '16 at 23:23
  • I want to set root shell to zsh
    – user196091
    Oct 23 '16 at 23:24
  • Don't use your user password at the prompt; use root's password.
    – Jeff Schaller
    Oct 23 '16 at 23:55
  • Already did login using root's password.
    – user196091
    Oct 23 '16 at 23:56
4

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 
3

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.

2
  • Why is it a bad idea to change root’s login shell to something other than /bin/sh?
    – k.stm
    Nov 30 '16 at 21:38
  • 1
    @k.stm The system is set up knowing the shell for root, so instructions are written based on that knowledge. /bin/sh might be staticly linked to avoid library dependencies. The new shell might require some files which are not available in the early boot stages. Given the cost of another couple of hundred bytes of disk space to create an additional account, it seems worthwhile to avoid all the unknown problems.
    – icarus
    Nov 30 '16 at 21:52
1

Just edit /etc/passwd using a text editor. There is one line for user root containing the current shell which you can change to zsh.

Don't log out to test the new settings but use a second terminal! Because in case you make a mistake you may not be able to login again to repair it.

0

You probably forgot to execute it has root. Execute the following command:

$ sudo chsh -s /bin/zsh
4
  • sudo chsh -s /bin/zsh asks for password which I enter correctly but still authentication failure.
    – user196091
    Oct 23 '16 at 23:29
  • If you don't know your own password I can't help. If you know the root password try execute just su before this command.
    – a0f3dd13
    Oct 23 '16 at 23:31
  • I am already logged in to root, as my question explained.
    – user196091
    Oct 23 '16 at 23:34
  • type "whoami" to see if you're really root ...
    – Michael D.
    Oct 24 '16 at 0:26
0

Editing passwd file with normal editor is not recommended to do this use

vipw

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

0

how about setting your default root shell using usermod utility:

sudo usermod --shell /bin/zsh root

works like a charm for me and its very simple.

you have proof in /etc/passwd line 1.

this is permanently and you dont have add any garbage to your .bashrc file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy