It's very weird that after switching to zsh from bash, I can't access root.

I normally use 'su' to login as root after I login as a normal user (username is normalusername) with less privileges. And it was always nice. But after switching root shell from bash to zsh, when I try to login via su, I got:

normalusername@(none):~$ su
Password: (enter the correct password)
Cannot execute zsh: No such file or directory

When I access root directly via ssh from my Mac, I got:

localhost:~ myname$ ssh -lroot
root@'s password: (enter the correct/incorrect password)
Permission denied, please try again.

No matter whether I entered the correct password, it comes again and again.

So I intentionally entered a wrong password with "su" from a normal user, I got:

normalusername@(none):~$ su
Password: (entered a wrong password and pressed enter)
(pressed enter)
su: Authentication failure

After entering the incorrect password I didn't see anything, I typed enter twice and then got the su: Authentication failure result.

I tried for many times and the conclusion is:

  1. If I enter the correct password, it will tell me that "Cannot execute zsh: No such file or directory"
  2. If I enter the incorrect password, it will not showing up anything until I hit enter for 2-6 times.

It seems to be an indication that I didn't just forget the "correct password". But how can I access root anyway?

The entry in /etc/passwd is

  • It looks like you have specified the new shell incorrectly. Did you enter the full path to zsh when you changed it? – D_Bye Jan 4 '15 at 12:37
  • 1
    @jimmij It's root:x:0:0:root:/root:zsh so it should be root:x:0:0:root:/root:/bin/zsh instead, right? How could I fix this? Thanks! – AGamePlayer Jan 4 '15 at 13:36
  • @AwQiruiGuo chsh allows you to change a user's shell. If you can't use it, or can't get permissions to, try to edit /etc/passwd directly. You may need sudo at some point ;) – John WH Smith Jan 4 '15 at 13:49
  • Just entered sudo vim /etc/passwd to edit it, before I was asked to enter a password, I got sudo: unable to resolve host (none) then I was prompted to enter the password for my current user. I entered and then I got this: normalusername is not in the sudoers file. This incident will be reported. – AGamePlayer Jan 4 '15 at 13:56
  • Use sh -s /bin/bash, then fix the problem. – ctrl-alt-delor Jan 17 '17 at 18:16

try: cd /usr/bin; su. Since you didn't give an absolute path to zsh. su is checking the PWD. changing to the directory zsh exists in will work on some systems. an example:

% su
su: zsh: No such file or directory
% cd /usr/local/bin
% su
# print $OSTYPE
  • 2
    And you won't ever have to use it again, because you are going to use absolute paths to the login shells right? :} – llua Jan 7 '15 at 16:07

Your entry in /etc/passwd is


This is an invalid entry: the shell must be a full path to an executable, the login program does not perform $PATH lookup.

You won't be able to log into the root account by normal means. You can use sudo to invoke a command, e.g. sudo vipw, if your account has sudo permissions. This is the only common method to bypass the login shell setting in the target account.

If you aren't a sudoer, you've probably locked yourself out of the root account. You'll need console access to repair the system. Boot in single user mode (see How do I run a command as the system administrator (root)) and edit /etc/passwd to contain


(with the correct path for zsh on your system).

Some administrators set up a toor account with UID 0 but a different shell (typically a statically linked binary such as sash, to allow root to log in even in case of a misconfiguration such as this one (the most common misconfiguration is a broken shared library in the normal shell).

To avoid such issues in the future, use the chsh command to change a user's shell, rather than editing /etc/passwd directly. And if you must edit /etc/passwd or some other file that is involved in gaining root access, keep a root shell open in a terminal and don't close it until you've verified that you can still log in as root.

  • Check your current shell with

    grep '^root:' /etc/passwd

    you should see at the end of the line full path to shell used by root user, like /bin/zsh. Then check if the path is not misspelled, file exists and has proper permissions set (read and execute).

  • If path was not correct then check where your zsh executable is placed with

    type zsh
  • After that su to root using the correct shell path, e.g. in case of /bin/zsh:

    su -s /bin/zsh -
  • Lastly run chsh to change default shell to /bin/zsh

  • 1
    @AwQiruiGuo what does ls -l /usr/bin/zsh show? – jimmij Jan 4 '15 at 14:03
  • 1
    @AwQiruiGuo and ls -l /etc/alternatives/zsh-usrbin? – jimmij Jan 4 '15 at 14:05
  • 1
    What's the difference between su -s /usr/bin/zsh and su -s /usr/bin/zsh - ? – PM 2Ring Jan 4 '15 at 14:06
  • 1
    @PM2Ring basically it sets all environment variables for login user, from manual: argument - may be used to provide an environment similar to what the user would expect had the user logged in directly. Compare for example echo $PATH with and without - argument. – jimmij Jan 4 '15 at 14:08
  • 1
    @jimmij So would leaving out the final - have caused the error mentioned in the 1st comment? – PM 2Ring Jan 4 '15 at 14:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.