Skip to content

Enhance: Run as another user through sudo #8

@zokusai

Description

@zokusai

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions