Operating System - HP-UX
1753532 Members
5436 Online
108795 Solutions
New Discussion юеВ

Re: Unix - Non Interactive SFTP using username and password

 
Anurag Mathur_1
New Member

Unix - Non Interactive SFTP using username and password

I am required to upload a file thru SFTP using a username and password. I am trying to write a non-interactive script to login and upload the file but the login fails.
$sftp -v -v -v -b password.bat testuser@16.181.138.176

(file password.bat contains only 1 line of text - the password for user testuser)

OpenSSH_4.5p1+sftpfilecontrol-v1.1-hpn12v14, OpenSSL 0.9.7l 28 Sep 2006
HP-UX Secure Shell-A.04.50.021, HP-UX Secure Shell version
debug1: Reading configuration data /opt/ssh/etc/ssh_config
debug3: RNG is ready, skipping seeding
debug2: ssh_connect: needpriv 0
debug1: Connecting to 16.181.138.176 [16.181.138.176] port 22.
debug1: Connection established.
debug1: identity file /home/carsint/.ssh/id_rsa type -1
debug1: identity file /home/carsint/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version WeOnlyDo 2.0.3
debug1: no match: WeOnlyDo 2.0.3
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.5p1+sftpfilecontrol-v1.1-hpn12v14
debug2: fd 5 setting O_NONBLOCK
debug3: RNG is ready, skipping seeding
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-g roup-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour1 28,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-c tr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour1 28,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-c tr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@open ssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@open ssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group1-sha1,diffie-hellman-group14-sha 1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cb c,rijndael128-cbc,rijndael192-cbc,rijndael256-cbc,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cb c,rijndael128-cbc,rijndael192-cbc,rijndael256-cbc,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-sha1,hmac-sha1-96,hmac-md5,none
debug2: kex_parse_kexinit: hmac-sha1,hmac-sha1-96,hmac-md5,none
debug2: kex_parse_kexinit: zlib,none
debug2: kex_parse_kexinit: zlib,none
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_init: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_init: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug2: dh_gen_key: priv key bits set: 132/256
debug2: bits set: 996/2048
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug3: check_host_in_hostfile: filename /home/carsint/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug1: Host '16.181.138.176' is known and matches the RSA host key.
debug1: Found key in /home/carsint/.ssh/known_hosts:1
debug2: bits set: 998/2048
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/carsint/.ssh/id_rsa (0)
debug2: key: /home/carsint/.ssh/id_dsa (0)
debug1: Authentications that can continue: password
debug3: start over, passed a different list password
debug3: preferred publickey
debug1: No more authentication methods to try.
Permission denied (password).
Connection closed

Please Help !! How do we provide the password for this login so that this could be run in the backround in a unix script?
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: Unix - Non Interactive SFTP using username and password

>(file password.bat contains only 1 line of text - the password for user testuser)

The whole purpose of ssh/sftp is to not supply a password. I doubt the -b option will provide it.
ssh can use "ssh-keygen" so you don't need a pass phrase.

Or "ssh-agent $SHELL", then ssh-add.
Steven Schweda
Honored Contributor

Re: Unix - Non Interactive SFTP using username and password

> I am required to upload a file thru SFTP
> using a username and password.

Why?

> $sftp -v -v -v -b password.bat testuser@16.181.138.176
>
> (file password.bat contains only 1 line of
> text - the password for user testuser)

What in "man sftp" suggests that that would
work?

I'd guess that "expect" could help you fake
interactive input to sftp, but I haven't
tried it. I'd also guess that most people
would rather set up publickey authorization,
and avoid fooling around with the interactive
password stuff.
Dennis Handly
Acclaimed Contributor
Steven E. Protter
Exalted Contributor

Re: Unix - Non Interactive SFTP using username and password

Shalom,

sftp is part of openssh/secure shell.

This suite permits you to use password free file transfer.

If you use the previously posted ssh-keygen procedure you should use scp to non-interactively transfer the files.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com