Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The package qqq.deb installs the program qqq that should run from uqqq user account. The package consist of the "qqq" program, "qqq.conf" config file and "/etc/init.d/qqq" initscript.

How should the package manage the creation of user "uqqq"? Are there any best practices or official guidelines about this?

  1. Just create the user automatically "uqqq" in postinst;
  2. Create the user automatically on first startup from /etc/init.d/qqq script;
  3. Create the user automatically on first startup of qqq program (without arguments)
  4. Don't create any user accounts, refuse to start unless the user is explicitly created by administrator (for example, using qqq --create-user);
  5. Don't create any user accounts, run unsafely from root by default;
  6. Interactively ask in postinst, init.d script or the "qqq" itself whether to create a user.

Should the package remove the user account when uninstalled?

share|improve this question

migrated from serverfault.com Sep 11 '12 at 23:24

This question came from our site for professional system and network administrators.

2  
The easiest way is to get to the answers of this question is to look at pre/post-installation scripts of official Debian packages. Just run grep adduser /var/lib/dpkg/info/*.postinst on any Debian based system to get many examples. –  jofel Oct 12 '12 at 14:53
add comment

3 Answers 3

up vote 7 down vote accepted

I'm not sure that this is an appropriate place to ask about package creation (especially if you plan on having the package accepted into Debian and/or being a package maintainer, in which case you'll need to see what Debian Policy says about user creation), but as an administrator installing packages I'd expect my packages to automatically create the users they require in either pre or postinst, so that any files required to be owned by the user may be made so before the program is run.

Your program should only run as root if it needs to (eg bind to privileged port) and ideally should drop its privileges once it's finished doing what required root.

You can look at how other (installed) packages have handled this by using

grep -l adduser /var/lib/dpkg/info/*postinst /var/lib/dpkg/info/*preinst

and reading the files listed (most take more than one line of options).

Oddly enough, all but one of my installed packages that create a user use adduser to add users, but the adduser package is not a required package, so your package will have to be built to depend on it. The useradd program is used by the libuuid1 package, and is part of the passwd package which is a required package.

share|improve this answer
add comment

Section 10.9. Permissions and owners in the Debian Policy Manual has what you are looking for (from "version 3.9.5.0, 2013-10-28"):

If you need to create a new user or group for your package there are two possibilities. Firstly, you may need to make some files in the binary package be owned by this user or group, or you may need to compile the user or group id (rather than just the name) into the binary (though this latter should be avoided if possible, as in this case you need a statically allocated id).

If you need a statically allocated id, you must ask for a user or group id from the base-passwd' maintainer, and must not release the package until you have been allocated one. Once you have been allocated one you must either make the package depend on a version of thebase-passwd' package with the id present in /etc/passwd' or /etc/group', or arrange for your package to create the user or group itself with the correct id (using adduser') in itspreinst' or postinst'. (Doing it in thepostinst' is to be preferred if it is possible, otherwise a pre-dependency will be needed on the `adduser' package.)

Note: The debian-devel list is quite active and answers such questions too (though that example is from 2003).

share|improve this answer
    
So, the short simplified answer is "Use adduser in postinst". –  Vi. Apr 11 at 1:29
add comment

"Are there any best practices or official guidelines about this?" -- yes, Debian has a whole raft of documentation available to help you build good package, including the Debian Policy manual, the Debian Developers' Reference, and so on -- all linked from http://www.debian.org/doc/. All your questions are answered in those documents.

share|improve this answer
3  
The link is too general. I already tried to quick-search like "Debian policy useradd" or "Debian policy create new user" but have not found anything useful. Please include the link to section that describes using "adduser" (or useradd?) to postinst (or preinst?), how the user should be named, what other things I need to think about... –  Vi. Aug 6 '12 at 20:42
1  
"RTFM" is an extremely unhelpful answer. –  Alex B Jan 8 at 10:46
    
@AlexB: Not on ServerFault, where this answer was originally posted. Feel free to have it deleted if you think it isn't useful here. Otherwise, a content-free comment on an 18 month old answer isn't particularly helpful, either. –  womble Jan 10 at 6:21
    
Very much not useful. Put some relevant links in there instead. –  Alexander Torstling Mar 24 at 16:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.