The Computer Oracle

Ubuntu: Accidentally changed root user to nonexistent shell

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Industries in Orbit Looping

--

Chapters
00:00 Ubuntu: Accidentally Changed Root User To Nonexistent Shell
00:26 Answer 1 Score 6
00:49 Accepted Answer Score 17
01:16 Answer 3 Score 2
01:48 Answer 4 Score 1
02:13 Thank you

--

Full question
https://superuser.com/questions/73407/ub...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#ubuntu #shell #useraccounts #root #chsh

#avk47



ACCEPTED ANSWER

Score 17


If you are able to login using your regular user, just change the root users shell directly:

sudo gedit /etc/passwd

Find the line for you root user, usually the first one, and change the last part from

...:bash

to

...:/bin/bash

And you should be good to go.

(NB: Replace gedit with whatever editor you fancy.)




ANSWER 2

Score 6


Use the Ubuntu install disk to boot the live session.

Mount the root ('/') partition on the harddisk (make sure it's writable).

edit '[HD mount point]/etc/passwd' (eg /media/sda1/etc/passwd),

root should be the first line, just correct the login shell which will be the last entry on the line.

Unmount harddisk. Remove CD. Reboot




ANSWER 3

Score 2


I played with this once ages ago:

cd /bin ; sudo su

What's happening is without a / in front the shell is being interpreted as a relative path. Oh gee if we are in /bin it resolves correctly.

If you get really stuck; the rescue CD is the long way around. The boot option init=/bin/sh gives you a root shell immediately. The cursor just blinks at you with no prompt but you have a root shell. Do

set -i
# mount / -o remmount,rw
# vi /etc/passwd
<fix it>
# mount / -o remount,ro
# reboot -f



ANSWER 4

Score 1


Note, as a short-term work-around, you can use the "-s" switch on the su command to specify a shell. For example:

su -s /bin/bash

would start your su session with the /bin/bash shell. Same goes for sudo su -s /bin/bash (or whatever shell you'd like) @Bjarke Freund-Hansen's answer is the permanent fix.