Take the 2-minute tour ×
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.

I tried to change the login shell.

Here's what the first line of /etc/passwd looks like (on a Debian Wheezy install):

rootx:0:0:root:/root:/:zsh

When I try to login as root:

Cannot execute zsh: No such file or directory

I know zsh is available:

$ which zsh
/usr/bin/zsh

Okay, it seems logical to replace zsh by its full path. But how can I do it?

I have one other user on the system (user), however it doesn't have root privileges and sudo is not installed on the system.

Assume that for whatever reason (encryption, physical access, ...) I cannot boot on a live CD to modify the file.

I do know, however, the credentials for the root account.

My question is: Is there any way, even programatically, to launch a process with the root account without launching its login shell first?

share|improve this question
    
what about su? or gksu? something like su -c 'sed -i s,root:/:zsh,root:/:/usr/bin/zsh, /etc/passwd' –  qdii May 12 '13 at 15:03
    
Shouldn't the line the passwd file been /usr/bin/zsh? Why did you put just the string zsh? –  slm May 12 '13 at 15:06
    
@slm That's the change the OP wants to make... –  Michael Kjörling May 12 '13 at 15:07
1  
if @qdii suggestion works (i.e. that su -c "<commands>" )work... could we not then simply use su -c "/bin/bash" to get to a working bash with user root? –  humanityANDpeace May 12 '13 at 15:16
1  
@humanityANDpeace: that's not supposed to work. The command passed to -c is run via the user's login shell. -s can be used to use another shell... only if the existing login shell is valid or the invoker is root. –  Mat May 12 '13 at 16:23

1 Answer 1

Have su permissions

You can use the following command to change any users' shell.

su -c "/usr/bin/chsh -s /bin/bash root"

If you have physical access

During your Grub boot you can get into any system so long as you have console access and there isn't a password preventing you from gaining access to the Grub menu.

During the initial boot up of the system when the Grub menu shows up, if you enter the menu and edit (press e key) the kernel line, you can add one of the following things to make the kernel boot in single user mode.

  • single
  • init=/bin/sh
  • 1

The line will look something like this:

 kernel /vmlinuz-2.6.15-27-386 root=/dev/mapper/Ubuntu-root ro init=/bin/bash

In Grub it should look similar to this:

       ss of grub

Once you've made the changes boot the kernel (press key b).

This will give you temporary access to the system with a shell where you can use vi/vim to make whatever changes you need to your /etc/passwd file. Just type reboot when you're done.

share|improve this answer
2  
He says he doesn't have physical access, thus likely he won't be able to see the GRUB menu. –  Renan May 12 '13 at 15:19
    
@Renan. OK I didn't get that from the first few reads. It's hidden in the line about the "..I cannot boot on a live CD.." which is phrased strangely to me. –  slm May 12 '13 at 15:28
4  
Your su command won't work, since it'll try to invoke root's shell, which doesn't exist. –  Gilles May 12 '13 at 20:49
    
@Gilles: Got any other ideas? I'm not seeing a way to fix this without physical access then. Feel like we're working against exactly what the system was designed to prevent at this point. –  slm May 12 '13 at 21:46
1  
@slm Without sudo, I think the root account is locked, so physical access is required. –  Gilles May 12 '13 at 21:49

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.