Operating System - HP-UX
1824976 Members
3983 Online
109678 Solutions
New Discussion юеВ

useradd and default shell

 
David Lodge
Trusted Contributor

useradd and default shell

Has anybody managed to get useradd to use a sensible shell (e.g. /usr/bin/sh) for the default shell (/sbin/sh) when creating a user.

The manual page for useradd (1M) states that the shell can be set as a default, but then contradicts itself when it describes the parameters.

Mangling the /etc/default/useradd file also failed to have any effect.
10 REPLIES 10
Rick Garland
Honored Contributor

Re: useradd and default shell

When you use the -s option with the useradd command, you are able to specify the shell.

'useradd -s /bin/ksh ...'

example snippet
David Lodge
Trusted Contributor

Re: useradd and default shell

Thanks, but I already knew that one :-)

What I want was a way to set the default shell that useradd uses when one isn't supplied on the command line.

It looks like useradd is set up to support it (like the RHEL version of useradd) but it doesn't work.
James R. Ferguson
Acclaimed Contributor

Re: useradd and default shell

Hi David:

Build a a wrapper script around the 'useradd' that sets the default shell argument to your choice and while passing the remaining arguments as is.

Regards!

...JRF...
Rick Garland
Honored Contributor

Re: useradd and default shell

Reviewing the man page for useradd, setting the default option for shell (-s) is not available.

useradd -D does not have the -s available. It is this -D switch that sets the defaults in the /etc/default/useradd file
David Lodge
Trusted Contributor

Re: useradd and default shell

I noticed that, but the section on -D states that you can supply a shell to it (which is like the Linux version of useradd).

I suspect this is a weird bug on HP-UX, or they they never fully implemented the default saving. It's strange as it would be useful and not too difficult to implement. (I suppose it's the same reason why /sbin/sh is the default shell.)

I can't use a wrapper as it's an external program that creates the accounts, plus I never like altering any thing in a package (because as soon as you patch it all breaks).

Arturo Galbiati
Esteemed Contributor

Re: useradd and default shell

Hi,
a possbile workaround id to write a script to chnage the shell for the user just created by chsh command.
Just my .002$.
HTH,
Art
RAC_1
Honored Contributor

Re: useradd and default shell

You can set default values for useradd with useradd -D command. Once set, those are used as default. Like follows.

useradd -D -s /usr/bin/ksh
Check it now.

useradd -D
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: useradd and default shell

/sbin/sh is the default which used by useradd in hp-ux. You can change the execution of useradd as,

alias useradd='useradd -s /usr/bin/sh'

like that. When you execute useradd it will use /usr/bin/sh as shell type for that user.

--
Muthu
Easy to suggest when don't know about the problem!
RAC_1
Honored Contributor

Re: useradd and default shell

You can also prepare a file /etc/default/useradd. In this file you can put following and these are taken as default values.

#default useradd options
HOMEDIR /home
GROUPID 20
INACT -1
EXPIRE
CHOWN_HOMEDIR no
SHELL /usr/bin/ksh
There is no substitute to HARDWORK
David Lodge
Trusted Contributor

Re: useradd and default shell

RAC: that's what I was trying to do (tested both). Unfortunately neither works on HP-UX 11.00.

This may be an 11.11 or 11.20 feature only :-(