3

Whenever I use the sudo -i command in the terminal, I get:

$ sudo -i
[sudo] password for user: 
sudo: /bin/bash/asd: command not found

The /bin/bash/asd was just some mistyped directory I entered previously.

Even after restarting and clearing the terminal history, sudo keeps giving me this error.

Is there any way to fix this?

Ravexina
  • 54,268
  • 25
  • 157
  • 179
user689123
  • 33
  • 1
  • 3

1 Answers1

2

It happened to me right now while testing that what can be the cause of the problem and sure it is because of a non-existent shell being set as root default shell.

I couldn't run any command with sudo, I wasn't able to run sudo -i, sudo -i /bin/bash or even sudo su -, because there is no /bin/bash/asd.

The only thing that I could do and it worked was running:

sudo -s /bin/dash

to get shell with root access, sudo -s /bin/bash should work too.

Then use nano to edit passwd file:

nano /etc/passwd

you should see a line look like this:

root:x:0:0:root:/root:/bin/bash/asd

change it to :

root:x:0:0:root:/root:/bin/bash

use Ctrl+O then pressing Enterto save the file.

Now use exit command to get out of dash shell which hasroot access.

You are done, however I suggest running:

sudo chsh root -s /bin/bash

to make sure permissions are correct.

Ravexina
  • 54,268
  • 25
  • 157
  • 179
  • So I did what you suggested and when I do sudo chsh root -s /bin/bash I get chsh: PAM: Authentication failure. – user689123 May 14 '17 at 21:46
  • Yes it does, you are not able to just run: `sudo chsh ...` to change the root shell becasue `sudo` does not work correctly right now as I described you should change `/etc/passwd` file manually. read my answer again; also Pay attention to the answer, I didn't say to change root shell to `/bin/bash/` I said change it to: `/bin/bash` :-) – Ravexina May 14 '17 at 21:54
  • Ok so I reread your solution and it does indeed work. Thanks! – user689123 May 14 '17 at 22:00
  • Glad that it was helpful, you're welcome ;) – Ravexina May 14 '17 at 22:01
  • There's also [an alternate way to bypass the `chsh` errors](https://askubuntu.com/a/848038/616451). – Chai T. Rex May 14 '17 at 22:39