i’ve been up for a really long time, so perhaps i’m missing something silly,
but this script ‘seems’ to work (all three dots are printed), but no id_rsa
file is made? do i have to signal the child to die or something? any other
useful debugging tips? it would be great if PTY could ‘tee’ it’s output to
stdout for debugging
PTY.spawn(‘ssh-keygen -t rsa’) do |r,w,cid|
r.expect %r/^Enter.:\s+/ do
print ‘.’
w.puts path
end
r.expect %r/^Enter.:\s+/ do
print ‘.’
w.puts ‘’
end
r.expect %r/^Enter.*:\s+/ do
print ‘.’
w.puts ‘’
end
w.flush
w.close
puts
end
-a
···
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================
i've been up for a really long time, so perhaps i'm missing something silly,
but this script 'seems' to work (all three dots are printed), but no id_rsa
file is made?
You must read its output
do i have to signal the child to die or something? any other
useful debugging tips?
i’ve been up for a really long time, so perhaps i’m missing something silly,
but this script ‘seems’ to work (all three dots are printed), but no id_rsa
file is made?
You must read its output
thanks guy - what exactly do you mean? there’s only one thing to read, and
reading it seems the throw errors:
PTY.spawn ‘ssh-keygen -t rsa’ do |r,w,cid|
r.expect %r/^Enter.:\s+/ do |line|
print line
w.puts path
end
r.expect %r/^Enter.:\s+/ do |line|
print line
w.puts ‘’
end
r.expect %r/^Enter.*:\s+/ do |line|
print line
w.puts ‘’
end
r.read # ?? this raises Errno::EIO
w.flush
w.close
puts
end
~/eg/ruby > ruby ssh-keygen.rb
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ahoward/.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again: ssh-keygen.rb:22:in read': Input/output error - /dev/pts/19 (Errno::EIO) from ssh-keygen.rb:22 from ssh-keygen.rb:8:in spawn’
from ssh-keygen.rb:8
without the read it generates the expected output, but no id_rsa file is
produced and no error is given… doesn’t the call to IO.expect do the reading
anyhow? also, the example in ext/pty/example_expect.rb doesn’t seem to do any
reading either?
do i have to signal the child to die or something? any other
useful debugging tips?
$expect_verbose = true
Guy Decoux
this is very helpful - and it was right in the example!
without the read it generates the expected output, but no id_rsa file is
produced and no error is given... doesn't the call to IO.expect do the reading
anyhow? also, the example in ext/pty/example_expect.rb doesn't seem to do any
reading either?
Without the read it don't give an error and don't generate the id_rsa
files.
With the read it give an error and generate the id_rsa files, no ?
At Thu, 15 Apr 2004 01:09:20 +0900,
Ara.T.Howard wrote in [ruby-talk:97152]:
~/eg/ruby > ruby ssh-keygen.rb
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ahoward/.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again: ssh-keygen.rb:22:in read': Input/output error - /dev/pts/19 (Errno::EIO) from ssh-keygen.rb:22 from ssh-keygen.rb:8:in spawn’
from ssh-keygen.rb:8
without the read it generates the expected output, but no id_rsa file is
produced and no error is given… doesn’t the call to IO.expect do the reading
anyhow? also, the example in ext/pty/example_expect.rb doesn’t seem to do any
reading either?
Because the watchdog thread created by PTY.spawn signals the
main thread when child exits, and read(2) is interrupted. In
such case, however, I feel that IO#read should return already
read data, if exists.
BTW, you don’t need PTY at all to generate ssh key
automatically.
$ rm -f id_rsa{,.pub}
$ ssh-keygen -t rsa -N “” -f id_rsa
Generating public/private rsa key pair.
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
42:1f:bc:76:60:45:a1:2b:fd:cc:4c:a2:3a:0c:87:c6 nobu@sharui.nakada.niregi.kanuma.tochigi.jp
you are a saint. why on earth would one be required to do a read which
generates an error? and why don’t the example scripts do this?
-a
···
On Thu, 15 Apr 2004, ts wrote:
without the read it generates the expected output, but no id_rsa file is
produced and no error is given… doesn’t the call to IO.expect do the reading
anyhow? also, the example in ext/pty/example_expect.rb doesn’t seem to do any
reading either?
Without the read it don’t give an error and don’t generate the id_rsa
files.
With the read it give an error and generate the id_rsa files, no ?
Then protect the read
Guy DEcoux
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================
At Thu, 15 Apr 2004 01:09:20 +0900,
Ara.T.Howard wrote in [ruby-talk:97152]:
~/eg/ruby > ruby ssh-keygen.rb
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ahoward/.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again: ssh-keygen.rb:22:in read': Input/output error - /dev/pts/19 (Errno::EIO) from ssh-keygen.rb:22 from ssh-keygen.rb:8:in spawn’
from ssh-keygen.rb:8
without the read it generates the expected output, but no id_rsa file is
produced and no error is given… doesn’t the call to IO.expect do the reading
anyhow? also, the example in ext/pty/example_expect.rb doesn’t seem to do any
reading either?
Because the watchdog thread created by PTY.spawn signals the main thread
when child exits, and read(2) is interrupted. In such case, however, I feel
that IO#read should return already read data, if exists.
perhaps a handle on an object which can be ‘closed’ could be returned instead
of an array of Files, etc:
passphrase = gen_random_passphrase
pty = PTY.spawn ‘ssh-keygen’
pty.stdin.puts ‘id_rsa.pub’
pty.stdin.puts passphrase
pty.stdin.puts passphrase
pts.close # do the right thing
pty = PTY.spawn ‘ssh-agent’
pty.stdin.write passphrase
…
BTW, you don’t need PTY at all to generate ssh key
automatically.
see above - i want to pass it to ssh-agent. thanks though, didn’t know
that…