Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance: Run as another user through sudo #8

Open
zokusai opened this issue Oct 10, 2014 · 0 comments
Open

Enhance: Run as another user through sudo #8

zokusai opened this issue Oct 10, 2014 · 0 comments

Comments

@zokusai
Copy link

zokusai commented Oct 10, 2014

Hi,

I have the need to impersonate the execution of the command to achieve a password-less connection to the remote server with a user other than the current one.

To make it, I count on sudo to do the work and use in my sources the following piece of code as a quick workaround:

module Rsync

  class << self
    attr_accessor :sudo_as
  end

  class Command
    def self.run(*args)
      cmd = "rsync --itemize-changes #{args.join(" ")}"
      cmd.insert(0, "sudo -u #{Rsync.sudo_as} ") if Rsync.sudo_as
      output = run_command(cmd)
      Result.new(output, $?.exitstatus)
    end
  end
end

Don't know if it's a good way to do it, but I hope will be of any help for a future enhancement.

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant