jh+ruby-lang
4/17/2008 6:04:00 PM
On Thu, 17 Apr 2008 12:48:03 -0500
James Dinkel <jdinkel@gmail.com> wrote:
> I'm establishing an ssh connection and then I want to run a command as
> sudo. Now, normally, the user will be prompted to put in a password to
> run the command as sudo.
>
> Here is my script:
> -----------
> Net::SSH.start( 'files02', 'myuser', 'mypassword' ) do |session|
> session.open_channel do |channel|
> channel.on_data do |ch, data|
> puts data
> end
>
> channel.exec "sudo echo \"hello\""
>
> end
>
> session.loop
> end
> ------------
>
> But this doesn't prompt for a password ( not surprisingly ) and of
> course doesn't run the command. Any ideas on how I could get the
> password prompt to the user?
a. Add user / command to /etc/sudoers, so a pasword is not required;
b. Ask for the password in your script, and then
channel.exec "echo #{password} | sudo -S echo \"r00ted\"".
In the latter case, don't blame me when you later suffer from a severe
case of unexpected local user privilege escalation.
-jh