Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano is hanging when prompting for SUDO password to an Ubuntu box

I have a capistrano deployment recipe I've been using for some time to deploy my web app and then restart apache/nginx using the sudo command. Recently cap deploy is hanging when I try to execute these sudo commands. I see the output: "[sudo] password for " With my server name and the remote login, but this is not a secure login prompt. The cap shell is just hanging waiting for more output and does not allow me to type my password in to complete the remote sudo command.

Is there a way to fix this or a decent work around? I did not want to remove the sudo password prompt of my remote user for web restart commands.

like image 474
MikeN Avatar asked Jan 10 '09 23:01

MikeN


People also ask

How do I force sudo to ask for password?

This feature can be enabled only by the superuser, however. Ordinary users can achieve the same behavior with sudo -k, which forces sudo to prompt for a password on your next sudo command.

Why does sudo keep asking for password?

Every time you issue a sudo command, Linux asks for your user password after a certain inactivity timeout, usually 5 minutes. This is the recommended behaviour to prevent unauthorised commands being run by someone or a malicious script in your absence.


3 Answers

This seems to happen when connecting to CentOS machines as well. Add the following line in your capistrano deploy file:

default_run_options[:pty] = true

Also make sure to use the sudo helper instead of executing sudo in your run commands directly. For example:

# not
run "sudo chown root:root /etc/my.cnf"

# but
sudo "chown root:root /etc/my.cnf"
like image 117
wulong Avatar answered Sep 30 '22 04:09

wulong


The other advice may be sound, but I found that once I updated to Capistrano 2.5.3 the problem went away. I have to make sure I stop running the default versions of tools that came with my O/S.

like image 23
MikeN Avatar answered Sep 30 '22 04:09

MikeN


# prevent sudo prompting for password
set :sudo_prompt, ""
like image 43
lemats Avatar answered Sep 30 '22 06:09

lemats