Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

change shell on login as root

diego mec
Occasional Contributor

change shell on login as root

Hi,
I have a problem with the shell of user root, I changed the default shell directly in /etc/passwd file (big mistake), removing /sbin/sh and inserting /usr/local/bin/bash. But this shell, bash, is not properly installed, so now I cannot login or su - root.
Of course, I am not able also to modify back this file since I cannot login as root.
If I do su - root, I get an error when the system tries to load the bash shell and am disconnected.
The server is remote so I cannot access the console.
Is there any means to login as root but using sh shell and then fix the problem?

Thanks


10 REPLIES
Torsten.
Acclaimed Contributor

Re: change shell on login as root

Never, never change root's shell in /etc/passwd.

Now try this:

# su root -c /sbin/sh

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Rajeev Shukla
Honored Contributor

Re: change shell on login as root

You shouldn't really change the shell of root coz root's shell should only reside in /sbin and also libraries required should be /lib which means only /sbin/sh is accepted as shell of root.
One way you could try is ftp the /etc/passwd to someother server, edit the file and put the file back using ftp.
Coz any other methods will use shell from passwd file and wont let you login.
Deepak Kr
Respected Contributor

Re: change shell on login as root

Yes, default shell for root user should never change to other like ksh or bash (in linux)...

This is HP recommendation also.

Doing ftp is good option as rajeev suggested..

"There is always some scope for improvement"
diego mec
Occasional Contributor

Re: change shell on login as root

Hi,
I already tested su - root -c /sbin/sh but does not work coz shell is loaded before.
I have tried your suggestion but ftp also fails... I see in syslog file:
FTP LOGIN REFUSED (shell not in /etc/shells)

Would it be possible to fix at least connecting on the console? I suppose that shell is not loaded in single-user osr something like that and /etc/passwd might be changed, or not

Thanks
Torsten.
Acclaimed Contributor

Re: change shell on login as root

If you bring down the server and boot again, the system will complain about the shell, stop boot and end with a /sbin/sh prompt.

The only problem is to bring down the system - last effort will be a power cycle or hard reset.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Robert-Jan Goossens
Honored Contributor

Re: change shell on login as root

Hi Diego,

Would it be possible to fix at least connecting on the console? I suppose that shell is not loaded in single-user osr something like that and /etc/passwd might be changed, or not

Yes, but you will have to reboot your server. You don't have to boot in to single user mode, this will be done automaticly.

Login
# mount -a
set your TERM
# vi /etc/passwd
and change the root shell back to /sbin/sh
:wq!
# shutdown -r -y now

Regards,
Robert-Jan
Rasheed Tamton
Honored Contributor

Re: change shell on login as root

Hi,

You have not really tried what Torsten suggested!

su root -c /sbin/sh

You still used a hyphen in front of the root. Use it without the hyphen (dash). Just use
su root

Rgds.
diego mec
Occasional Contributor

Re: change shell on login as root

Hi,
in fact I did test all possibilities, including without the hyphen:
som@gpparlay[HP-UX]:/home/som# su root -c /sbin/sh
Password:
/usr/lib/hpux32/dld.so: Unable to find library 'libtermcap.so'.
Killed
Heironimus
Honored Contributor

Re: change shell on login as root

If you have sudo you can use it to invoke a shell as root. sudo does not rely on the shell defined in /etc/passwd.

If you have an NFS mount you might be able to put a setuid shell on the server and run it on the client to get root access.
James R. Ferguson
Acclaimed Contributor

Re: change shell on login as root

Hi Diego:

You could perform an "expert recovery" from your core media, loading a virgin copy of '/usr/newconfig/etc/passwd' to remaster a valid '/etc/passwd' which you then subsequently fix or restore:

http://docs.hp.com/en/5992-3336/ch13s03.html

Regards!

...JRF...