Tell me more ×
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
1  
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

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

2 Answers

up vote 4 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

"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
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

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.