How to reload nginx of remote server using cron as root user How to reload nginx of remote server using cron as root user nginx nginx

How to reload nginx of remote server using cron as root user


You can execute the command as root by doing:

systemctl --host root@example.com reload nginx

The example.com host needs to PermitRootLoginAs you don't want to prompt for password you need to create a certificate just like you did rsync and stick it into ./ssh/


Install sudo on the remote server (if not already installed). Then configure it to allow ubuntu user to execute service nginx reload command as root without password prompt. Something like the following in sudoers file:

ubuntu ALL=(root) NOPASSWD: /usr/sbin/service nginx reload

And now to reload nginx you just run (from ubuntu user):

sudo -n service nginx reload


If you start your nginx server as ubuntu (ssh -i /home/ubuntu/key.pem" ubuntu@example.com:/etc/nginx), you don't need to reload as root.

You can send the reload signal to the current nginx process:

ssh -i /home/ubuntu/key.pem" ubuntu@example.com:/etc/nginx -s reload