jordanpg
jordanpg

Reputation: 6516

Capistrano with only 'sudo su - user' allowed

I'm trying to do an uncomplicated Rails/Capistrano deployment to a remote server. Unfortunately I can't get sudo to run correctly out of the box. I need to deploy here:

drwxr-xr-x 2 user   www       4096 Sep 28 15:05 my_app_dir

and sudoers has been set up to allow me to run sudo su - user and that's it.

Some attempts to coax this into working from deploy.rb:

set :use_sudo, true
set :sudo, 'sudo su - user'  # fails due to bad su syntax, -c is inserted after user
set :sudo, 'sudo -u user'  # fails because it's not set up
set :sudo, 'sudo su - user -c' # also bad syntax
set :sudo_prompt, ''

I gather than the best options are to either:

  1. Enable password-less sudo (recommended here)
  2. Enable sudo -u user, which should work with set :sudo, 'sudo -u user'

Any ways to make this work as is?

Upvotes: 5

Views: 2019

Answers (1)

Máté
Máté

Reputation: 2345

Is your user that you're trying to use added to the sudoers cfg on the server? Try this

run "#{sudo :as => 'bob'} mkdir /path/to/dir"

source

Upvotes: 1

Related Questions