Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a debian package, I want to install the files to the directory /home/user/myapp instead of /usr/bin

but after install the deb, the owner of /home/user/myapp is root

I hope after install the deb, the owner should be user, so I add postinst to do the post-work:

chown -R user /home/user/myapp

but I always got an error "chown: ... Operation not permitted"

any helps?


share|improve this question

migrated from stackoverflow.com Oct 28 '11 at 11:06

This question came from our site for professional and enthusiast programmers.

This belongs on Superuser, but I've answered anyway. – detly May 13 '11 at 1:32
up vote 4 down vote accepted

The whole point of a Debian package is to install system-wide software. Think about it: if multiple users install this package to their respective /home/user/myapp area, what should show up in your package manager?

If you want to install to your home directory, use the original source (eg. tarball) distribution.

share|improve this answer
Thanks a lot for your clue – camino May 13 '11 at 2:10
@camino - most tarball installation scripts allow you to set things like "PREFIX" and "LIB"... you should ask the developers of whatever it is you're trying to install for help with user-area installation. – detly May 13 '11 at 2:28

you need to make a routine in the package's postinstall that copies the contents of what you need to put on the user's home

Something like this:

# For every user in /home/ ...
for HOME_U in /home/*?; do

# Obtain the username
USER=$( basename ${HOME_U} )

# In case the user is active (exists in /etc/shadow) ...
if [ $( grep -c "${USER}:.*:.*:.*:.*:.*:::" /etc/shadow ) == 1 ] \
&& [ $( grep -c "${USER}:.*:.*:.*:.*:.*:/bin/.*sh" /etc/passwd ) == 1 ] \
&& [ -d ${HOME_U}/.config ] \
&& [ -d ${HOME_U} ]; then

# Making sure .config/your-package/ exists
mkdir -p /home/${USER}/.config/your-package/

# with appropiate permissions
chown ${USER}:${USER} /home/${USER}/.config/your-package/

# copy what we need
cp /etc/skel/.config/your-package/x.conf /home/${USER}/.config/your-package/
cp /etc/skel/.config/your-package/y.conf /home/${USER}/.config/your-package/
cp ... /home/${USER}/.config/your-package/

# with appropiate permissions
chown ${USER}:${USER} /home/${USER}/.config/your-package/x.conf
chown ${USER}:${USER} /home/${USER}/.config/your-package/y.conf


Hope you can use it.

share|improve this answer
The list of subdirectories in /home is NOT a list of users (even if it often looks like it). On most Linux systems, you could check UID_MIN and UID_MAX in /etc/login.defs, and then extract the info from the /etc/passwd lines where the UIDs are in the range. If you have LDAP, you need to parse the output of the getent passwd command instead. If the system uses NIS, I think you need yet something else. – mivk Nov 3 '12 at 15:49

Your Answer


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.