DEV Community

Cover image for Register a Linux user to the nginx group
Rusydy
Rusydy

Posted on

Register a Linux user to the nginx group

Case

Upon completing the setup of the GCP instance, NGINX, and cloning the repository, I was unable to pull the repository and received the following error message:



[username@instance-1 landing-page]$ git pull

fatal: detected dubious ownership in repository at '/var /www/landing-page'
To add an exception for this directory, call:
git config --global --add safe.directory /var /www/landing-page


Enter fullscreen mode Exit fullscreen mode

Solution

I then realized that I had forgotten to add my user to the NGINX group and change the ownership of the directory, which have caused the issue.

To register a Linux user to the nginx group, follow these steps:

  • Check the current groups that the user belongs to by running the following command:


groups username


Enter fullscreen mode Exit fullscreen mode
  • If the user does not belong to the nginx group, add the user to the group using the usermod command:


sudo usermod -a -G nginx username


Enter fullscreen mode Exit fullscreen mode
  • To verify that the user has been added to the nginx group, run the groups command again:


groups username


Enter fullscreen mode Exit fullscreen mode

The output should show the user as a member of the nginx group.

To change the ownership of the directory, run the following command:



[username@instance-1 www]$ chown -R username:nginx landing-page/


Enter fullscreen mode Exit fullscreen mode

Note: The above steps assume that the nginx group already exists on your system. If it does not, you can create the group using the following command:



sudo groupadd nginx


Enter fullscreen mode Exit fullscreen mode

Top comments (0)