IO.popen and ssh

P

Paul Lynch

I've been having some trouble using IO.popen to control an ssh process
(and also mysqldump) on Linux. My understanding is that if I do:
p = IO.popen('ssh mymachine')
then the input and output of the ssh subprocess should be accessible via
p. However, when I try that in an irb shell, the ssh process
immediately takes over the standard input and output of irb, and I get
an "Enter password:" prompt. I have to hit control-c to get back to the
irb prompt.

Is there a workaround for this? Or should I be doing this a different
way? Thanks,
--Paul
 
K

Konrad Meyer

--nextPart1255216.zSbRIA3GXW
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Quoth Edwin Van leeuwen on Tuesday 11 September 2007 08:59:39 am:
=20
Why not use Net::SSH to connect directly from ruby?
http://net-ssh.rubyforge.org/chapter-2.html#s1

Because at least in my experience, it doesn't work? :D

=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart1255216.zSbRIA3GXW
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBG5t8KCHB0oCiR2cwRArEmAKCZs0JESWWMhkyoPh9PBS5Qkeez3ACggDmp
sbmMeDopD99/VFDxEs0SObY=
=rK8l
-----END PGP SIGNATURE-----

--nextPart1255216.zSbRIA3GXW--
 
A

ara.t.howard

I've been having some trouble using IO.popen to control an ssh process
(and also mysqldump) on Linux. My understanding is that if I do:
p = IO.popen('ssh mymachine')
then the input and output of the ssh subprocess should be
accessible via
p. However, when I try that in an irb shell, the ssh process
immediately takes over the standard input and output of irb, and I get
an "Enter password:" prompt. I have to hit control-c to get back
to the
irb prompt.

Is there a workaround for this? Or should I be doing this a different
way? Thanks,

ssh requires a pty to read the password. note that this is NOT the
same as STDIN, which is what you get with IO.popen. you need to use
the built-in pty lib to control ssh that way and it's still fraught
with peril. it's much, much, much, much better to setup ssh keys for
password-less access (no passwords in scripts), and to spawn a simple
command, such as /bin/sh, on the remote end to read pre-generated
commands (a script).

regards.

a @ http://drawohara.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top