quicktile icon indicating copy to clipboard operation
quicktile copied to clipboard

Don't create files with root perms on non-root pip cache directory

Open luzfcb opened this issue 4 years ago • 0 comments

Description

This pr update the docs and some scripts to include -H argument on sudo when using pip to avoid creating files with root permissions on non-root pip cache directory

Rationale

After pip 6.0.0 (I don't remember which exact version this was included with.), by default pip creates a cache directory in $HOME/.cache/pip/ and store the wheel/egg packages. The $HOME is the current user home directory.

When we use:

sudo pip3 install some-package

pip will continue to use the current user's pip cache directory, however, new files and directories within the cache folder will be created with the owner defined as root, that is, we will end up having files and a directory inside the current user home that the current user cannot read or write without root permission.

This is not a problem that pip can solve on its own. This is where the sudo -H argument comes in. The best explanation of what -H does comes from the sudo documentation

     -H, --set-home
                 Request that the security policy set the HOME environment variable to the home
                 directory specified by the target user's password database entry.

That is, with sudo -H pip will use /root/.cache/pip instead of /home/<my-user>/.cache/pip/.

Whenever we need to install some python package with pip and sudo is necessary, it is recommended to use -H in sudo to avoid future headaches.

luzfcb avatar Apr 11 '21 12:04 luzfcb