Capistrano with only 'sudo su - user' allo

2019-02-22 09:44发布

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?

1条回答
Evening l夕情丶
2楼-- · 2019-02-22 10:18

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

查看更多
登录 后发表回答