Operating System - HP-UX
1833178 Members
2879 Online
110051 Solutions
New Discussion

Re: how to change user's shell

 
SOLVED
Go to solution
thebeatlesguru
Regular Advisor

how to change user's shell

user A shell is /usr/bin/sh
i want to change it to /sbin/sh
i use root to change it in /etc/passwd
but when i use A login ,the shell is still /usr/bin/sh

what should i do?
hihi
10 REPLIES 10
Steven Sim Kok Leong
Honored Contributor

Re: how to change user's shell

Hi,

Verify the change by typing:

# grep userid_A /etc/passwd

Hope this helps. Regards.

Steven Sim Kok Leong
Steven Sim Kok Leong
Honored Contributor

Re: how to change user's shell

Hi,

To be on the safe side, always use the vipw command when changing the /etc/passwd.

Hope this helps. Regards.

Steven Sim Kok Leong

Extracted man page information for your convenience:

vipw edits the password file while setting the appropriate locks, and does any necessary processing after the password file is unlocked. If the password file is already being edited, you will be told to try again later. The vi editor is used unless the environment variable EDITOR indicates an alternate editor. vipw performs a number of consistency checks on the password entry for root, and does not allow a password file with an incorrectly formatted root entry to be installed.
thebeatlesguru
Regular Advisor

Re: how to change user's shell

i use grep userid_A /etc/passwd
and this change has done

what command i can use to show which shell i am using now?
hihi
Steven Sim Kok Leong
Honored Contributor

Re: how to change user's shell

Hi,

The following will indicate the shell you are currently using:

# ps -fp $$

Using echo $SHELL is unreliable eg. after you run another child shell in your login session.

Hope this helps. Regards.

Steven Sim Kok Leong
Wilfred Chau_1
Respected Contributor
Solution

Re: how to change user's shell

Logon as root, then

# usermod -s /sbin/sh

# grep /etc/passwd
now the shell for the user has been changed.

have fun!
Wilfred Chau_1
Respected Contributor

Re: how to change user's shell

Also check the user's .profile. Make sure
SHELL is not set there.

After you logon as A, type "echo $SHELL" to
check the current shell you are using.

Hope this helps.
thebeatlesguru
Regular Advisor

Re: how to change user's shell

before changeing:ps -fp $$
UID PID PPID C STIME TTY TIME COMMAND
snmp 5994 5993 1 10:29:29 pts/ta 0:00 -sh

after root change shell ,and use vipm

ps -fp $$

UID PID PPID C STIME TTY TIME COMMAND
snmp 5994 5993 1 10:29:29 pts/ta 0:00 -sh

nothing happen?
hihi
Steven Sim Kok Leong
Honored Contributor

Re: how to change user's shell

Hi,

/sbin/sh and /usr/bin/sh functions similarly.

ps -fp $$ is good in identifying child shells:

$ /sbin/sh
$ ps -fp $$
UID PID PPID C STIME TTY TIME COMMAND
xyz 7600 4268 0 10:29:59 pts/0 0:00 /sbin/sh
$ /usr/bin/sh
$ ps -fp $$
UID PID PPID C STIME TTY TIME COMMAND
xyz 7658 7600 0 10:30:09 pts/0 0:00 /usr/bin/sh

For the login shell, using echo $SHELL works if it has not been tampered with ie. you can set in your /etc/profile:

readonly SHELL

Hope this helps. Regards.

Steven Sim Kok Leong
Steven Sim Kok Leong
Honored Contributor

Re: how to change user's shell

Hi,

What I meant is that -sh will appear regardless of whether it is /sbin/sh or /usr/bin/sh in your process list if one of them is used as the login shell.

If you have lsof installed, you can identify the binary used by:

# lsof|grep $$

Hope this helps. Regards.

Steven Sim Kok Leong
Bill Hassell
Honored Contributor

Re: how to change user's shell

Any user can change their own shell. The command is:

chsh

The sbin versions of commands (and the POSIX shell sh) are archived libraries which means they will occupy slightly more RAM as they don't share common library functions. Otyher than the RAM increase, there is no downside to using the /sbin/sh shell. The uoside (for root only) is that this shell is mandatory in single user mode as /usr/lib is not mounted.


Bill Hassell, sysadmin