How to use Github hooks when you disabled the root user

For security reasons, I disabled the root user and created a new user to use SSH.

When I use rsync, I rsync to the /home/my-name/my-dir directory and then mv to the /var/www/html/my-dir director, then used sudo chown -R www-data:www-data my-dir.

I’d like to create a Github hook that when I push to the repo, pulls the repo to my droplet.

Q1. Should I pull to /home/my-name/my-dir and them moved to the /var/www/html/my-dir and use chown command to change the owner?

Q2. Is there any tutorial how to set this up?

Thank you.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
April 14, 2021
Accepted Answer

Hi there,

What I could suggest is allowing your non-root user to run this one specific command with sudo without being prompted for a password.

You can configure that you can change the sudoers file on your server. The correct way to make changes to the sudoers file is by using the following command:

sudo visudo

At the bottom of the file add the following:

your_user_here ALL = NOPASSWD: /bin/chown -R www-data\:www-data /path/to/your-dir

Then save and exit. After that when you run sudo /bin/chown -R www-data\:www-data /path/to/your-dir with your non-user you will not be prompted for your sudo password.

Hope that this helps. Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel