Operating System - HP-UX
1844138 Members
2600 Online
110228 Solutions
New Discussion

why root's shell is /sbin/sh?

 
bhupesh m
Frequent Advisor

why root's shell is /sbin/sh?

man 4 passwd:
The login shell for the root user (uid 0) must be /sbin/sh. Other shells such as sh, ksh, and csh are all located under the /usr directory which may not be mounted during earlier stages of the bootup
process. Changing the login shell of the root user to a value other than /sbin/sh may result in a non-functional system.

why? Changing the login shell of the root user to a value other than /sbin/sh may result in a non-functional system. ??

15 REPLIES 15
Pete Randall
Outstanding Contributor

Re: why root's shell is /sbin/sh?

The main reason is so that you have a shell available to you in single user mode when the the other file systems (such as /usr) are not mounted.


Pete

Pete
Mel Burslan
Honored Contributor

Re: why root's shell is /sbin/sh?

think a little harder.

whe the system boots, root is the owner of vital processes and needs a shell to run some commands. Right ?

when the system boots, the only filesystem available for use is / where /sbin resides on.

if you specify a shell residein under /usr for instance, if root can not run any commands prior to this shell loaded, how are you going to mount the filesystem. Do you see the catch-22 situation here ?
________________________________
UNIX because I majored in cryptology...
bhupesh m
Frequent Advisor

Re: why root's shell is /sbin/sh?

s. understood that.
if i changed the shell of a root, then i cant go to single user mode. that is fine. but, as long as not necessary to go to single user mode, it should function. isnt?

and one more question:
passwd -sa
giving PS and LK.
expand this PS and LK..
Patrick Wallek
Honored Contributor

Re: why root's shell is /sbin/sh?

All items in /sbin/ are STATICALLY linked binaries. That means that all libraries that they need to function are a part of the execuatable program.

All items in /usr/bin are dynamically linked, which means that in order to run, the /usr/lib area needs to be available.

Now, when the machine starts, it needs to do things via the shell, so it uses the /sbin/sh shell. A lot of the things are done BEFORE any of the other filesystems are mounted, so /usr is NOT available. So if you attempted to use /usr/bin/sh as the shell, it would attempt to access that shell and it would not be available, thus breaking your system.

If you really want to see what happens, find a TEST system, change the shell to /usr/bin/sh, and then reboot the system. Make sure you have a console attached so you can watch the progress and see what happens.
A. Clay Stephenson
Acclaimed Contributor

Re: why root's shell is /sbin/sh?

No. Never change root's shell. The shell in /sbin is a statically linked version of the POSIX shell and it is fully functional. It is not a Bourne shell and there is really no reason to change it. If you want to use bash or some other shell then explicitly execute after logging in as root. The fundamental problem is that many of the rc commands execute before any other filesystems (especially /usr with the shared libraries) are mounted. So how do you plan to reach multi-user mode when the rc scripts can't execute?
If it ain't broke, I can fix that.
bhupesh m
Frequent Advisor

Re: why root's shell is /sbin/sh?

s. guru's. i understood that. my question is:
1. if i changed the shell for root, system should function properly till the next reboot. isnt?
2. is the system will allow to change the shell for a root? or it wont allow?
3. if a root user mistakenly changed his shell, and system also rebooted then there will be no way to fix the problem. isnt? or there any method is available?
bhupesh m
Frequent Advisor

Re: why root's shell is /sbin/sh?

sorry patrick. i cant test that, since i dont have a test system.
A. Clay Stephenson
Acclaimed Contributor

Re: why root's shell is /sbin/sh?

1. if i changed the shell for root, system should function properly till the next reboot. isnt?
TRUE

2. is the system will allow to change the shell for a root? or it wont allow?

Yes, you can change it BUT be prepared for the consequences on reboot.

3. if a root user mistakenly changed his shell, and system also rebooted then there will be no way to fix the problem. isnt? or there any method is available?

There are many methods to fix it. 1) Install your boot disk(s) in another machine, mount them, edit /etc/passwd to change the shell. 2) Boot from recovery media. 3) Reload the OS. ...

There are many ways to "fix" this but it is stupid to ever get in this situation. It usually occurs because somebody from Linux loves bash and "fixes" his HP-UX box. If you are really going to do this then it would be possible to create a stically linked version of a shell but it would still be dumb.
If it ain't broke, I can fix that.
bhupesh m
Frequent Advisor

Re: why root's shell is /sbin/sh?

thanks clay. understood clearly.

and passwd -sa
giving PS and LK.
what is this PS and LK?
Torsten.
Acclaimed Contributor

Re: why root's shell is /sbin/sh?

1. if i changed the shell for root, system should function properly till the next reboot. isnt?

A: Yes.

2. is the system will allow to change the shell for a root? or it wont allow?

A: root can do everything (even mistakes) ;-)

3. if a root user mistakenly changed his shell, and system also rebooted then there will be no way to fix the problem. isnt? or there any method is available?

A: The system will give an error "NO SHELL" and cannot execute the init process. It will probably fall back to single user mode and stop there (AFAIR).

Don't change root's shell!

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!   
spex
Honored Contributor

Re: why root's shell is /sbin/sh?

Hi,

PS and LK are values for password status.

PS = valid password
LK = locked account
NP = no password

PCS
Bill Hassell
Honored Contributor

Re: why root's shell is /sbin/sh?

And just to amplify a bit -- you normally jsut reboot the system and everything comes up normally. The only time you need single user is when there is a serious problem. But if you changed root's shell and a few minutes later your system crashes and you need single user mode to repair the problem, you have no prompt because there is no /usr directory and you can't issue any commands at all. Simply put, you will have lost the entire system. Recovery may not be possible.

Now if this is a toy system to play with, this may not be much of an issue, but if you depend on this system, never change root's shell. NOTE: it is a common mistake to login as root when it is not required and this leads to all sorts of serious problems including the notorious "rm -rf *" mistake. You don't want any special shell for root -- ever. At most, you'll use root to run maintenance commands and perhaps vi to edit some config files. Otherwise, always avoid logging in as root.


Bill Hassell, sysadmin
Tim Nelson
Honored Contributor

Re: why root's shell is /sbin/sh?

Why not just execute the new shell at the end of root's .profile. When in single user you will just get an error but all will still work.

or even better.

When logging in in as root type /usr/bin/ksh, now you are using the korn shell, etc. When you log out you are back to normal.

dictum9
Super Advisor

Re: why root's shell is /sbin/sh?

hpux should have /bin/ksh available in single user mode.

My guess is, they keep /bin/sh because it's smaller and less complex. ksh is good but I've had it crash on hpux more than once.
Patrick Wallek
Honored Contributor

Re: why root's shell is /sbin/sh?

Actually nothing in /bin is available in single-user mode. /bin is a (transition) link to /usr/bin and since /usr is not mounted in single-user mode, you will not have anything there available. /bin has been this way for several years, since at least HP-UX 10.20.

/sbin is the directory that is available in single-user mode. The only shell that is available in /sbin is sh.

/sbin does NOT have a statically linked version of ksh or any other shell.