Interacting with a shell script (ssh)

from a (j)ruby script, I’ll launch a shell script asking for a pass
phrase (ssh authentification).

obviously I’ll ask the user to enter he’s pass phrase before lauching
ssh.

but how could i know, after having launched ssh, the shell script is
waiting for an input ?

On Jul 21, 2008, at 10:34 PM, Une Bévue wrote:

from a (j)ruby script, I’ll launch a shell script asking for a pass
phrase (ssh authentification).

obviously I’ll ask the user to enter he’s pass phrase before lauching
ssh.

but how could i know, after having launched ssh, the shell script is
waiting for an input ?

not easily.

  • use ssh keys and specify only key auth so it fails otherwise
  • use net/ssh
  • use a pty to provide the password
  • rely on ssh-agent
  • do hairly io operations to enter the passprase yourself

those are really the options

a @ http://codeforpeople.com/

ara.t.howard [email protected] wrote:

not easily.

  • use ssh keys and specify only key auth so it fails otherwise
  • use net/ssh
  • use a pty to provide the password
  • rely on ssh-agent
  • do hairly io operations to enter the passprase yourself

first thanks for your reply.

firstly, i’ve tried without ruby, from zsh shell.

if i don’t use ssh-agent like :
$ ssh -p 2222 [email protected]
Enter passphrase for key ‘/Users/yt/.ssh/id_dsa’:
Permission denied (publickey).

NO access in that case.

however using ssh-agent that way :

$ eval ssh-agent -s
Agent pid 2044

$ ssh-add ~/.ssh/id_dsa
Enter passphrase for /Users/yt/.ssh/id_dsa:
Identity added: /Users/yt/.ssh/id_dsa (/Users/yt/.ssh/id_dsa)
$ echo $SSH_AUTH_SOCK
/tmp/ssh-kbqXlJAxOy/agent.2043
$ ssh -p 2222 [email protected]


| || | |__ || _ || _ || | | |
|
|| __| ___ | | | |
| || |
| || |
__ |____ |
| | | | || || ||||||||
|
| |
| Bienvenue sur le Twin Tact !!!
Last login: Tue Jul 22 08:31:35 UTC 2008

exit

Connection to 169.254.0.2 closed.

$scp -P 2222 Sun_URLs.txt [email protected]:/mnt/fat
Sun_URLs.txt 100% 307 0.3KB/s 00:00

then, using ssh-agent, i can do what i want.

why such a difference ?

obviously have tried also using net/ssh and net/scp (+Highline) with
ruby :

require ‘net/ssh’
require ‘net/scp’

Net::SSH.start(“169.254.0.2”, “root”, :password => “”,
:port => 2222) do |ssh|
ssh.scp.upload! “/mnt/fat”, “/Users/yt/Desktop/scp_ESSAIS.txt”
end

here i got :

Enter passphrase for /Users/yt/.ssh/id_dsa:
/opt/local/lib/ruby/gems/1.8/gems/net-ssh-2.0.3/lib/net/ssh.rb:195:in
`start’: root (Net::SSH::AuthenticationFailed)
from ./net-scp.rb:15

then net/ssh is asking for the pass phrase althought it’s given by
:password

may be there is another option for the passphrase not being the same as
:password ?

On 22.07.2008, at 10:04, Une Bévue wrote:


------8<------
why such a difference ?

Login without sending a password over the network by use of public/
private key
method. Read wikipedia or other resources, there are really thousands
of good
ones.

:password

may be there is another option for the passphrase not being the
same as
:password ?

According to http://net-ssh.rubyforge.org/ssh/v2/api/index.html the
password
option is not used as passphrase to open your private key.

:password => the password to use to login

:passphrase => the passphrase to use when loading a private key

(default is
nil, for no passphrase)

regards, Sandor
Sz

Sandor Szücs [email protected] wrote:

Login without sending a password over the network by use of public/
private key
method.

It’s what i’ve done but working only when using ssh_agent.

Read wikipedia or other resources, there are really thousands
of good
ones.

didn’t see anyone explaining why key auth works with ssh_agent and not
directly and also why, when logged as root it works directly.

:passphrase => the passphrase to use when loading a private key

(default is
nil, for no passphrase)

ok, now i’ve catched this option…

On 22.07.2008, at 16:54, Une Bévue wrote:

didn’t see anyone explaining why key auth works with ssh_agent and not
directly and also why, when logged as root it works directly.

Ok you did your homework. :slight_smile:

Without information I can just guess, but I think it has to be a
configuration failure. Maybe you should ask better a ssh-user
mailinglist.
[email protected]

Provide them your ssh version and output of ssh -vvv, then I am sure
they
will understand and solve your problem.

regards, Sandor
Szücs

Sandor Szücs [email protected] wrote:

will understand and solve your problem.

regards, Sandor Szücs

OK, thanks, i’ll have a look there.
In fact on side I’m using OpenSSH over Mac OS X 10.4.11 and dropbear (a
tiny ssh over handheld phone) the other side, dropbear isn’t complete as
openssh because of size restriction.