title: How can I switch user in a Capistrano task?
body: <p>I made a small test task below:</p>
  
  <pre><code>set :user, "user"
  set :password, "password"
  set :root_password, "root password"
  set :use_sudo, false
  role :srv, "exmaple.com"
  
  task :show_info do
      run "iptables -L", :shell =&gt; "su -" do |channel, stream, data|
          channel.send_data("#{root_password}\n")
      end
  end
  </code></pre>
  
  <p>This server doesn't allow me to use <code>sudo</code>, so I have to login as a normal user then become root.</p>
  
  <p>I have also tried to create <code>surun</code> from <a href="http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/#comment-42918" rel="nofollow">this article</a>, though it doesn't help me... :(</p>
  
  <p>Could someone please tell me the promising method to run command after switching to root in Capistrano?</p>
  
  <p>Thanks in advance.</p>
  
  <p><em>P.S.</em> Added the output log:</p>
  
  <pre><code>$ cap show_info
    * executing `show_info'
    * executing "iptables -L"
      servers: ["example.com"]
      [example.com] executing command
      command finished in 000ms
  failed: "su - -c 'iptables -L'" on example.com
  </code></pre>