2

I tried installing zsh on ubuntu ( 14.04). When I switched to zsh, I was unable to go into super user mode.

If I do a su it asks for passwd and on entering the correct password, it says:

Cannot execute which zsh: No such file or directory

But when I enter an incorrect password and press enter 4-5 times, it shows nothing.

On checking my /etc/passwd file, it showed:

root:x:0:0:root:/root:which zsh

I tried to edit the file and save but it shows

Unable to save /etc/passwd

I have tried to change the runlevel to 1 via grub, but it results in an error:

APCI PCC probe failed

I am running Ubuntu on VirtualBox.

2
  • Ubuntu grub has option to go into recovery. Also, you can change an option to boot into bash directly. Can't recall which, though Commented May 9, 2016 at 13:21
  • even during recovery; setting root: Drop out to root shell asks for passwd, which when entered correct gives: which zsh: No such file or directory
    – iyerrama29
    Commented May 10, 2016 at 6:25

5 Answers 5

1

You should remove from the password file the which word... It should be something like :

root:x:0:0:root:/root:/bin/zsh

Where /bin/zsh is the path to the Z shell binary.
In the current config, the login process is trying to execute which zsh and that command is failing.

Also, edit the file as root, with sudo vim /etc/passwd for example because it is a file which is writable only by root.

If you can't sudo or su, then boot into recovery mode (choose Advanced option for Ubuntu in GRUB boot loader, then choose Ubuntu...(recovery mode), then choose root/Drop to root shell prompt). After this, remount the / filesystem as read-write (mount -o remount,rw /) and then you can edit the content of the /etc/passwd file. Tested this on Ubuntu 16.04.

6
  • Hi there, I tried editing the file, but as I mentioned above, it shows I cannot edit the file(unless I am the root - and also I am unable to become the root because the su command doesn't work): Unable to save /etc/passwd
    – iyerrama29
    Commented May 9, 2016 at 13:20
  • Filesystem is mounted read only. Try remount as read write Commented May 9, 2016 at 13:22
  • I tried going to /etc and doing mount -o remount rw and got mount: only root can do that
    – iyerrama29
    Commented May 9, 2016 at 13:38
  • 1
    boot into recovery mode (choose Advanced option for Ubuntu in GRUB boot loader, then choose Ubuntu...(recovery mode), then choose root/Drop to root shell prompt). After this, remount the / filesystem as read-write (mount -o remount,rw /) and then you can edit the content of the /etc/passwd. Tested this on Ubuntu 16.04.
    – magor
    Commented May 9, 2016 at 14:13
  • I booted into the recovery mode and chose: root: Drop out to root shell prompt, it again gives: Give the root password for maintainence or press Ctrl+D to continue, on giving the right password, it shows which zsh: No such file or Directory
    – iyerrama29
    Commented May 10, 2016 at 4:35
1

You cannot edit files from the Grub prompt (Grub can only read files, it doesn't have any write support). You need to boot Linux¹.

If you can't log in normally, you can completely bypass the normal boot process and start just a kernel and a shell. At the Grub prompt, press e to edit the boot sequence, add init=/bin/bash to the end of the linux=… line, and press Ctrl+X to boot. You'll get a root shell and nothing else. Run

mount -t proc proc /proc
mount -o remount,rw /

Now run chsh -s /bin/zsh root to repair your user database.

Next, reboot with Alt+SysRq+U followed by Alt+SysRq+B, or boot normally with

mount -o remount,ro /
umount /proc
exec /sbin/init

Tip: run chsh without a user argument. That way, it validates the shell.

Tip: when you're changing some configuration, always keep a shell open and test the configuration. If you made a mistake, you'll still have a command line to repair it.

Tip: you can create a toor account with UID 0 (so it's still root), with the same password as root, and where the shell remains /bin/sh, so that you keep another way to log in if things break. Better yet, install a statically linked shell (busybox-static or zsh-static) and use that as toor's login shell.

¹ Or you can use guestfs if the host is Linux.

1
  • Thanks a lot for the great trick with changing the init! It helped me in a situation where I had to edit fstab to allow normal booting :-)
    – luckyrumo
    Commented May 4, 2018 at 19:56
0

If you know the root password, you can run su -s /bin/bash to get a root bash shell.

sudo -s /bin/bash should work too, and depending on how sudo is configured you'll either need to know only your own password or no password.

You can then use chsh -s /bin/bash to change root's shell back to bash.

BTW, it's generally a bad idea to change root's shell on any unix system. Many cron jobs etc depend on root's shell being the default root shell for that OS and WILL break if you change it.

0

The solution which we have tried is using init command.

I have executed the command init 1 on terminal and then able to login using root user.

Once authenticated, edited the /etc/passwd file to change the shell from /bin/zsh to /bin/sh.

Once this is done, able to login using root user.

-2

Pls try sudo vi /etc/passwd And enter your currently logged user password.

Also you can find shell correct path in /etc/shell

And to check current shell pls try echo $SHELL

3
  • As I mentioned, I cannot do a sudo or a su, when I do sudo it shows: sudo: /usr/bin/sudo must be owned by uid 0 and have setuid bit set and on su it asks for passwd but when entered correct password it gives ** Cannot execute which zsh: No such file or directory**
    – iyerrama29
    Commented May 9, 2016 at 13:41
  • -1, I'm afraid everything you suggest is wrong: 1) The OP can't use sudo as explained in their question; 2) You mean /etc/shells not /etc/shell; 3) $SHELL doesn't show the currently running shell, it shows the default for the user. In any case, how is that relevant?
    – terdon
    Commented May 9, 2016 at 13:43
  • /etc/shell will not give you the required output.
    – AReddy
    Commented May 13, 2016 at 6:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .