Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I mistakenly entered

chsh -s /usr/bin 

instead of

chsh -s /bin/bash 

and now I can't log into a root shell, how do I start a bash shell as root manually ?

share|improve this question
    
in what context did you do this. In a current terminal, for the users default shell? – jgr208 Mar 28 at 13:17
    
dont you have users in the sudo group? – Rui F Ribeiro Mar 28 at 13:26
    
@RuiFRibeiro I do but when I run sudo bash or sudo chsh -s /bin/bashit asks me for a password and whether I give the one from the user or from root it says chsh: PAM: Authentication failure – ChiseledAbs Mar 28 at 13:28
2  
does sudo vipw work? – Rui F Ribeiro Mar 28 at 13:30
1  
@RuiFRibeiro yes it did thanks, I wasn't aware I could change the default root shell in that file – ChiseledAbs Mar 28 at 13:32
up vote 26 down vote accepted

While root does not have access, a user in the sudo group can still run privileged commands - it seems the error is not in sudo, but elsewhere in the sudo chshcommand (e.g. chsh error). As such your sudo is apparently working.

The passwd file can be edited with:

sudo vipw

And the root shell changed manually.

(first line of /etc/passwd usually)

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

Fom man vipw

The vipw and vigr commands edits the files /etc/passwd and /etc/group, respectively. With the -s flag, they will edit the shadow versions of those files, /etc/shadow and /etc/gshadow, respectively. The programs will set the appropriate locks to prevent file corruption.

share|improve this answer
3  
I never knew about vipw and vigr, thank you! I always used sudo vim /etc/passwd – cat Mar 28 at 15:54
3  
You might be interested in visudo sudo.ws/man/1.8.15/visudo.man.html too, @tac – Rui F Ribeiro Mar 28 at 16:05
3  
Or sudo -e, that performs this locking-editing feature for any edit. – kojiro Mar 28 at 21:54

Another option, assuming you have access to another account, is to manually override the default shell by using su --shell=/bin/bash:

-s, --shell=SHELL
run SHELL if /etc/shells allows it

The primary advantage of this is that it only requires access to another account, not another privileged one.

share|improve this answer

For security reasons, logins whether textual or graphical and utilities like su and sudo that allow you to run commands as a different user all run those command through the target user's shell. If the target user's shell is non-functional, well, you've seen the results :-(

Unless you happen to have a still-functional root shell running somewhere or something like a setuid-root binary or something that allows you to bypass this, rebooting and correcting the problem using a rescue system or live image is probably your best bet.

Boot the rescue system, mount your real system's root filesystem somewhere, say, /mnt/foo, and edit /mnt/foo/etc/passwd to fix the shell. Save, unmount, and you're done.

share|improve this answer
    
curious, what happens if you do this and the /etc/passwd file is in a hash instead of plain text? – jgr208 Mar 28 at 13:18
1  
/etc/passwd is not plaintext? I haven't seen that in at least, like, a decade. Is that still a thing on some systems? Anyway, I guess chroot /mnt/foo chsh -s /bin/bash might do the trick in that case? – Celada Mar 28 at 13:21
    
I have never had the problem described, however I work with locked down systems that need to have /etc/passwd not in plain text as to avoid hackers and the such compromising the system even more if they gain access. Hmm that might work, lets just say I hope i never have to try and see if it works actually. – jgr208 Mar 28 at 13:24
    
I was able to edit /etc/passwd with sudo from a user account, I wasn't aware that the shell was defined in this file, thanks – ChiseledAbs Mar 28 at 13:34
    
@ChiseledAbs oh, you were? Good for you, glad you solved your problem. I didn't think it would let you. – Celada Mar 28 at 13:36

Add init=/bin/bash to your kernel command line ( if booting with grub, press e to edit the boot entry ), and you will have a bash shell running as root without even having to supply a password. Your root filesystem likely will still be mounted read only though, so you will need to remount it first, then you can change the shell back with chsh.

share|improve this answer

sudo usermod -s /bin/bash jdoe

will change the shell of jdoe to bash. You can then sudo egrep jdoe /etc/passwd to verify.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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