So I want to be able to cap:deploy without having to type any passwords. I have setup all private keys so I can get to the remote servers fine, and am now using svn over ssh, so no passwords there.
I have one last problem, I need to be able to restart nginx. Right now I have sudo /etc/init.d/nginx reload. That is a problem b/c it uses the capistrano password, the one I just removed b/c I am using keys. Any ideas on how to restart nginx w\out a password?
Create a rake task in
Rails_App/lib/capistrano/tasks/nginx.rake
and paste below code.Then ssh to your remote server and open file
and the paste this line (after line
%sudo ALL=(ALL:ALL) ALL
)Or, as in your case,
Here I am assuming your deployment user is
deploy
.You can add here other commands too for which you dont require to enter password. For example
I just spent a good hour looking at sudoer wildcards and the like trying to solve this exact problem. In truth, all you really need is a root executable script that restarts nginx.
Add this to the /etc/sudoers file
Write script as root
Make the script executable
Test.
There is a better answer on Stack Overflow that does not involve writing a custom script:
Instructions:
In all commands, replace myuser with the name of your user that you want to use to restart nginx without sudo.
Open sudoers file for your user:
Editor will open. There you paste the following line. This will allow that user to run nginx start, restart, and stop:
Save by hitting ctrl+o. It will ask where you want to save, simply press enter to confirm the default. Then exit out of the editor with ctrl+x.
Now you can restart (and start and stop) nginx without password. Let's try it.
Open new session (otherwise, you might simply not be asked for your sudo password because it has not timed out):
Stop nginx
Confirm that nginx has stopped by checking your website or running
ps aux | grep nginx
Start nginx
Confirm that nginx has started by checking your website or running
ps aux | grep nginx
PS: Make sure to use
sudo /usr/sbin/service nginx start|restart|stop
, and notsudo service nginx start|restart|stop
.