Re: adding users...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-07-18 at 23:41 -0600, Bob Proulx wrote:
> Jason Pyeron wrote:
> > When a package needs to verify/add a user, what are the proper ways of 
> > adding users on install and removing them on uninstall?
> > 
> > This question may be vague, if so my apologies for that.
> 
> Proper depends upon the distro for which you are packaging.  On some
> distros you would use 'useradd' and on others 'adduser'.  So with an
> equally vague answer, it depends.  You have to know your audience.
> 
> Hints:
> 
> * Test that the user does not already exist.  Create the user if it
>   does not.
> 
> * How do you handle NIS/YP?  Do you care?

LDAP too, and yes you should care.

> %pre
> 
> if ! grep -q '^myuser:' /etc/group; then
>   groupadd -g 26 myuser 2>/dev/null || true
> fi
> if ! grep -q '^myuser:' /etc/passwd; then
>   useradd -u 26 -o -g 26 -c Myuser -d /var/myuser -s /bin/false myuser 2>/dev/null || true
> fi
> 
> exit 0

A better check that takes into account LDAP/NIS, etc is to use the
"gentent" command.

Also, best practice is to use the "-r" switch to user/groupadd to create
system accounts with low ids.

So taking these two suggestions into account, you have:

%pre

if ! getent group | grep -q myuser; then
   groupadd -r myuser 2>/dev/null || true
fi
if ! getent passwd | grep -q myuser; then
  usreadd -r -g myuser -c Myuser -d /var/myuser -s /bin/false myuser 2>/dev/null || true
fi

exit 0

Dax Kelson
Guru Labs


[Index of Archives]     [RPM Ecosystem]     [Linux Kernel]     [Red Hat Install]     [PAM]     [Red Hat Watch]     [Red Hat Development]     [Red Hat]     [Gimp]     [Yosemite News]     [IETF Discussion]

  Powered by Linux