0

I have a problem to login as root.
My '/etc/passwd' file is like

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

I asked similar question at "How can I change the shell for to original one (/bin/bash) without root privilege?" and I the proposed suggestions, but till now it doesn't work.

[]@[]:~$ su - root
Password:
Cannot execute which zsh: No such file or directory
[]@[]:~$ su - -s /bin/bash
Password:
Cannot execute which zsh: No such file or directory
[]@[]:~$ su - -s /bin/bash root
Password:
Cannot execute which zsh: No such file or directory
[]@[]:~$ su -s /bin/bash root
Password:
Cannot execute which zsh: No such file or directory

Any suggestions for this situation?

2 Answers2

0

Use the following command, replacing /bin/sh with your preferred shell:

SHELL=/bin/sh sudo -s

This command first sets the SHELL environment variable temporarily to /bin/sh or whatever shell you chose. Then it invokes sudo -s which logs into the shell defined by the SHELL variable.

See the example terminal log. Note the ps output which once shows bash (my default shell) and once sh as second process in the hierarchy, as well as the different prompts.

$  sudo -s
root: ~ #  ps
  PID TTY          TIME CMD
23103 pts/2    00:00:00 sudo
23104 pts/2    00:00:00 bash
23146 pts/2    00:00:00 ps
root: ~ #  exit
ipc-admin: ~ $  SHELL=/bin/sh sudo -s
# ps
  PID TTY          TIME CMD
23190 pts/2    00:00:00 sudo
23191 pts/2    00:00:00 sh
23200 pts/2    00:00:00 ps
# exit
$
0

Try to change the runlevel at boot time, and to start with runlevel 1.
Then you will be root and you can edit each file.

If using LILO, access the boot: prompt by typing [Ctrl]-[X]. Then type:

linux 1

If using GRUB, follow these steps:

  • In the graphical GRUB boot loader screen, select a label and press [e] to edit it.
  • Arrow down to the kernel line and press [e] to edit it.
  • At the prompt, type the number of the runlevel you wish to boot into (1 through 5), or the words single or emergency and press [Enter]. In your case 1
  • The GRUB screen reappears with the kernel information. Press the [b] key to boot the system.

When you are in single user mode, you are root. Use vi (or nano or pico ...) and correct your /etc/passwd file.

Reference:

Hastur
  • 19,483
  • 9
  • 55
  • 99