# Need help. want to use Net::sh to do sudo command

**URL:** <https://www.ruby-forum.com/t/need-help-want-to-use-net-sh-to-do-sudo-command/112398>\
**Category:** Ruby\
**Created:** [August 18, 2007, 11:36am UTC](https://www.ruby-forum.com/t/need-help-want-to-use-net-sh-to-do-sudo-command/112398 "2007-08-18T11:36:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 18, 2007, 11:36am UTC](https://www.ruby-forum.com/t/need-help-want-to-use-net-sh-to-do-sudo-command/112398/1 "2007-08-18T11:36:35Z")

</div>

I want to do a sudo command to change permissions on our server  
because our admin has some kind of build  
that blows away the image directory and it ends up having the wrong  
permissions after the build.  
When the sudo command is run it will prompt for a password and I need  
to write the password to it. If I just write to the stream before it  
prompts, I’m not sure if it will work ? Also if someone could give me  
the exact stuff that they think will work, that would be helpfull as I  
am concerned if I play with it and have failed attempts it might lock  
my account. I want to be able to email the group and say, 'hey here is  
a script that runs every 10 minutes from my pc and fixes the build  
problem", If possible, I don’t want the admins to be upset with me for  
getting my account locked because I was playing around. Our server  
runs linux, thanks. Below is sort of what my script would do, but the  
password part is missing. As I said, it may be an easy thing, I’m just  
affraid of getting it wrong …

* * *

require ‘net/ssh’

host = ‘[myhost.frog.surf.com](http://myhost.frog.surf.com)’

Net::SSH.start( host,  
:password=\>‘candy’,  
:port=\>22,  
:username=\>‘ljkid’  
) do |session|  
cmd = ‘sudo chmod 777 /apps/mystuff/images’  
session.process.popen3(cmd) do |stdin,stdout,stderr|  
puts stdout.read  
end

end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 18, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/need-help-want-to-use-net-sh-to-do-sudo-command/112398/2 "2007-08-18T22:41:05Z")

</div>

On Aug 18, 2007, at 02:35, removed\_email\_address@domain.invalid wrote:

> my account. I want to be able to email the group and say, 'hey here is
> 
> ```
> puts stdout.read
> end
> 
> ```
> 
> end

Why bother with Net::SSH?

require ‘open3’

Open3.popen3 “ssh hostname sudo ls” do |i,o,e|  
i.puts “your password”  
puts o.read  
end

PS: I hope that isn’t your password
