I can't tell precisely what context your code fits in, so some general comments: when debugging things with SSH, it is often quite enlightening to crank up the verbosity. It can get pretty chatty, but it's generally pretty straightforward to understand.
As Andrew points out, SSH could be trying to still ask a human for the password (this is typically called "keyboard-interactive" authentication, as opposed to simply "password"). SSH (well, OpenSSL) works very hard in order to determine the controlling terminal so that it can ask the real user sitting at the keyboard to enter their password. There are ways of providing input, but they involve workarounds like the above-mentioned SSH_ASKPASS or (if I recall) things like allocating a PTY for the SSH process to act as its terminal. Generating an SSH keypair and using authorized_keys is a common way to allow scripts and other more-automated processes access to passwordless login, and combined with an SSH agent can pose minimal extra security exposure (with a keypair that has a passphrase; this also requires passing through a few variables from the environment to the SSH process). I believe there is a program called
sshpass that uses some of these workarounds if you have a way to bundle that with your app and using keys is, for whatever reason, not practicable.
On Tue, Sep 11, 2012 at 8:23 PM,
<zhub...@gmail.com> wrote:
Hi all,
on remote machine, the command is scp, and it need a pasword to input.
then i create a new reader
pw := strings.NewReader("xxxxxxxxx\r")
and assign it to the session
session, err := this.conn.NewSession()
defer session.Close()
if err != nil{
return err
}
session.Stdout = w
session.Stderr = w
session.Stdin = pw
if err := session.Start(cmd); err != nil {
log.Println(err)
return err
}
if err := session.Wait(); err != nil {
log.Println(err)
return err
}
But seems it does not take effect, the sctp always prompt me "permission denied",
but the password is obviously right.
I also tried
pw := strings.NewReader("xxxxxxxxx\n")
pw := strings.NewReader("xxxxxxxxx")
all these not worked.
Is there something wrong with my code?
Thanks!
--