From: "Ara.T.Howard" Date: 2004-04-15T15:49:25+09:00 Subject: Re: ruby pty/expect help On Thu, 15 Apr 2004 nobu.nokada@softhome.net wrote: > Hi, > > At Thu, 15 Apr 2004 12:09:12 +0900, > Ara.T.Howard wrote in [ruby-talk:97212]: > > 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 > > Yes, I've thought about same strategy for open3. have you seen my session-2.1.6 package which wraps open3 in this way? it is more specific but same idea... > ssh-agent doesn't read passphrase but prints some environment variables and > runs as a daemon, like as: right, right... i've slept three hourse in the last 48... basically i'm just trying to get around security ;-) > > $ ssh-agent > SSH_AUTH_SOCK=/tmp/ssh-FGmutb8164/agent.8164; export SSH_AUTH_SOCK; > SSH_AGENT_PID=8165; export SSH_AGENT_PID; > echo Agent pid 8165; > > Therefore you should set those variables instead. e.g., > > `ssh-agent`.scan(/^(SSH_[A-Z_]+)=([^; ]*)/, &ENV.method(:[]=)) ^ ^ ^ i learn something every day i guess that makes it a block - neat. > > Then, you'll need to send passphrase to ssh-add. At this time, > you have 2 methods: > > 1) with pty. > PTY.spawn("ssh-add") do |r,w,pid| > r.expect %r/^Enter.*:\s+/ {w.puts passphrase} > end > > 2) without control terminal. Since ssh-add reads passphrase > from stdin when no ctty or X are available, you can: > > IO.popen("-", "w") do |f| > if f > f.puts passphrase > else > ENV.delete("SSH_ASKPASS") > ENV.delete("DISPLAY") > Process.setsid > exec("ssh-add") > end > end > > or, if setsid command is available and env command has -u option: > > IO.popen("env -u SSH_ASKPASS -u DISPLAY setsid ssh-add", "w") do |f| > f.puts passphrase > 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 :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================