3

Running Ubuntu 22.04 in an LXC. git version is 2.34.1. Installed a web application under the user 'brian' but none of the calls to git work (this works fine on an PiOS system - git 2.20.1).

I have found I am getting a return error of 128 and trying to run git commands from the command line as www-data user, result in the error

fatal: detected dubious ownership in repository at

From the announcement of 2.36 https://github.blog/2022-04-18-highlights-from-git-2-36/#stricter-repository-ownership-checks it look like this should be fixed by adding a safe.directory option.

However, I am running 2.34.1. I have tried to use this command

git config --global --add safe.directory '*'

(with and without sudo) as the user brian, to no effect - the error continues.

I also tried it for the specific directory as well, with no success.

Any suggestions how to fix?

7
  • 1
    you need to execute the command as the user receiving the error (www-data)
    – dan1st
    Dec 18, 2022 at 20:06
  • Tried ` sudo -u www-data git config --global --add safe.directory '*'` and I get the error error: could not lock config file /var/www/.gitconfig: Permission denied
    – Brian
    Dec 18, 2022 at 20:38
  • Maybe the '*' syntax is not supported in your version. Try adding the full path (as the command should be outputed by git in your error message)
    – Philippe
    Dec 18, 2022 at 23:23
  • User www-data does not have permission to update (or perhaps create, or both) "his" (its) own config file. You can do what you did (--system) if you're willing to disable all security for all users, or you can just create or update the /var/www/.gitconfig file by whoever it is that does have permission to create it. It's probably wisest to use the narrowest safe.directory setting possible: e.g., list just the directory or directories that should be considered safe.
    – torek
    Dec 19, 2022 at 5:46
  • 1
    The result you got implies the latter (that user www-data has /var/www set as its $HOME).
    – torek
    Dec 19, 2022 at 22:31

1 Answer 1

8

The answer (for me currently) is to use --system rather than --global

This command worked on a fresh install (sudo if not root);

git config --system --add safe.directory '*'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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