Ubuntu – Can apt actions delete/modify files inside exiting user home

apthome-directorypackaging

I somehow always assumed that when I run a command like apt-get install, remove, purge then at most apt might add configuration dot-files files to my existing local home (not even sure about that), but NEVER modify or delete any files there (without backing up).

Is there any such restriction or at least guideline?

Best Answer

There are two issues:

  1. Debian policy dictates how home directories are managed and properly packaged .deb should not modify anything in users home directories.

9.2.3. Non-existent home directories The canonical non-existent home directory is /nonexistent. Users who should not have a home directory should have their home directory set to this value.

The Debian autobuilders set HOME to /nonexistent so that packages which try to write to a home directory will fail to build.

10.7.5. User configuration files (“dotfiles”) The files in /etc/skel will automatically be copied into new user accounts by adduser. No other program should reference the files in /etc/skel.

Therefore, if a program needs a dotfile to exist in advance in $HOME to work sensibly, that dotfile should be installed in /etc/skel and treated as a configuration file.

However, programs that require dotfiles in order to operate sensibly are a bad thing, unless they do create the dotfiles themselves automatically.

Furthermore, programs should be configured by the Debian default installation to behave as closely to the upstream default behavior as possible.

Therefore, if a program in a Debian package needs to be configured in some way in order to operate sensibly, that should be done using a site-wide configuration file placed in /etc. Only if the program doesn’t support a site-wide default configuration and the package maintainer doesn’t have time to add it may a default per-user file be placed in /etc/skel.

/etc/skel should be as empty as we can make it. This is particularly true because there is no easy (or necessarily desirable) mechanism for ensuring that the appropriate dotfiles are copied into the accounts of existing users when a package is installed.

See : https://www.debian.org/doc/debian-policy/ for details


HOWEVER .....

  1. Installing .deb requires root authorization and packages can run pre and post install scripts that modify files in home directories in violation of debian policy or people who package .deb may choose to ignore debian policy.

So it is possible for .deb to violate debian policy and alter files in user home directories.

This is one of many considerations or reasons you should be very careful when installing .deb from outside the Ubuntu repositories.