Matěj Koubík
Matěj Koubík

Reputation: 1147

How to switch remote user in Capistrano

In capistrano, I can set the :user variable to determine which user is logged to ssh, when executing remote commands. But I'd like to execute commands as different users depending on task. Is it possible? Something like run "command", :as => "bob" would be nice.

Upvotes: 1

Views: 954

Answers (1)

mpapis
mpapis

Reputation: 53178

The docs: https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Invocation-Run

You could use combination of :shell and &block:

run "echo am i bob ? :$USER:", :shell => "su - bob -s bash" do |channel, stream, data|
  channel.send_data("#{bob_password}\n")
end

Upvotes: 2

Related Questions