# Using Net SSH to issue command on remote windows XP

**URL:** <https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854>\
**Category:** Ruby\
**Created:** [October 14, 2008, 8:04am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854 "2008-10-14T08:04:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 14, 2008, 8:04am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/1 "2008-10-14T08:04:21Z")

</div>

Hi,

I want to issue window’s DOS commands like “dir, cp, del…”  
on a remote Windows XP machine.  
I have installed OPENSSH on the remote windows machine  
and trying to use the Net SSH.  
I cannot get any of the DOS commands to work on the remote machine.

Any help ???

Thanks  
Saritha

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 14, 2008, 8:56am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/2 "2008-10-14T08:56:18Z")

</div>

Saritha Y. wrote:

> Hi,
> 
> I want to issue window’s DOS commands like “dir, cp, del…”  
> on a remote Windows XP machine.  
> I have installed OPENSSH on the remote windows machine  
> and trying to use the Net SSH.  
> I cannot get any of the DOS commands to work on the remote machine.
> 
> Any help ???
> 
> Thanks  
> Saritha

what is your source(current) machine is it linux or windows ?

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 14, 2008, 9:39am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/3 "2008-10-14T09:39:55Z")

</div>

Pokkai D. wrote:

> Saritha Y. wrote:
> 
> > Hi,
> > 
> > I want to issue window’s DOS commands like “dir, cp, del…”  
> > on a remote Windows XP machine.  
> > I have installed OPENSSH on the remote windows machine  
> > and trying to use the Net SSH.  
> > I cannot get any of the DOS commands to work on the remote machine.
> > 
> > Any help ???
> > 
> > Thanks  
> > Saritha
> 
> what is your source(current) machine is it linux or windows ?

My source/Current machine is Windows

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 14, 2008, 11:51am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/4 "2008-10-14T11:51:42Z")

</div>

Hi,

2008/10/14 Saritha Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Thanks  
> Saritha

Try psexec.exe ( download at [http://live.sysinternals.com/psexec.exe](http://live.sysinternals.com/psexec.exe) )

You can do remote command like this:

psexec \192.168.0.1 -u administrator -p password cmd.exe /c dir

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 15, 2008, 4:20am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/5 "2008-10-15T04:20:14Z")

</div>

2008/10/15 Saritha Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 
> 
> machines.  
> Is there any utility in ruby to issue command on remote windows machine.

What’s your problem with Net SSH?

1. Install OpenSSH server

2. Create an user account for SSH

3. In OpenSSH bin folder  
mkpasswd -l user \>\> ../etc/passwd

4. Run following code.

require ‘net/ssh’  
host = ‘127.0.0.1’  
user = ‘test’  
password = ‘test’  
command = ‘cmd.exe /c dir’  
Net::SSH.start( host, user, :password=\> password) do |ssh|  
puts “Opened Connection to #{host}”  
puts ssh.exec!( “#{command}”)  
puts “Closed Connection to #{host}”  
end

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 15, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/6 "2008-10-15T12:11:40Z")

</div>

On Tue, Oct 14, 2008 at 5:33 PM, Saritha Y.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Sure can  
the only question is what shell you will use than! SSH is only the  
transport layer, the application layer still is a different story.  
I guess this is often forgotten when using it between 2 Linux boxes as  
the application layers are so obviously compatible…

However if you installed openSSH with cygwin your shell should be bash  
would this do? IIRC there is nothing DOS can do what bash cannot.

HTH  
Robert

–  
C’est véritablement utile puisque c’est joli.

Antoine de Saint Exupéry

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 15, 2008, 10:59pm UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/7 "2008-10-15T22:59:27Z")

</div>

Robert D. wrote:

> On Tue, Oct 14, 2008 at 5:33 PM, Saritha Y.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> Sure can  
> the only question is what shell you will use than! SSH is only the  
> transport layer, the application layer still is a different story.  
> I guess this is often forgotten when using it between 2 Linux boxes as  
> the application layers are so obviously compatible…
> 
> However if you installed openSSH with cygwin your shell should be bash  
> would this do? IIRC there is nothing DOS can do what bash cannot.
> 
> HTH  
> Robert
> 
> –  
> C’est vï¿½ritablement utile puisque c’est joli.
> 
> Antoine de Saint Exupï¿½ry

I have done as quoted by Park.  
My ssh.exec! is not recognized.  
Here is the error I get.

Opened Connection to  
10.10.12.21c:/ruby/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/session.rb:199:in  
`method_missing' : undefined method `exec!’ for #Net::SSH::Session:0x34ad4d8  
(NoMethodError)

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 16, 2008, 3:12am UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/8 "2008-10-16T03:12:34Z")

</div>

2008/10/16 Saritha Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > However if you installed openSSH with cygwin your shell should be bash  
> > I have done as quoted by Park.  
> > My ssh.exec! is not recognized.  
> > Here is the error I get.
> 
> Opened Connection to  
> 10.10.12.21c:/ruby/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/session.rb:199:in  
> `method_missing' : undefined method `exec!’ for #Net::SSH::Session:0x34ad4d8  
> (NoMethodError)

I tested with net-ssh-2.0.4  
BTW, gem install net-ssh  
failed with Zlib::BufError  
So I installed it by downloading zip file.

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![saritha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@saritha](https://www.ruby-forum.com/u/saritha)\
**Post date:** [October 14, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/using-net-ssh-to-issue-command-on-remote-windows-xp/150854/9 "2008-10-14T17:33:59Z")

</div>

Heesob P. wrote:

> Hi,
> 
> 2008/10/14 Saritha Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Thanks  
> > Saritha
> 
> Try psexec.exe ( download at [http://live.sysinternals.com/psexec.exe](http://live.sysinternals.com/psexec.exe) )
> 
> You can do remote command like this:
> 
> psexec \192.168.0.1 -u administrator -p password cmd.exe /c dir
> 
> Regards,
> 
> Park H.

Thanks Park !

Can Net SSH be used if OPENSSH is installed for windows ?  
since I’m using ruby Net SSH for issuing commands on remote linux  
machines.  
Is there any utility in ruby to issue command on remote windows machine.

Thanks  
saritha
