non-interactive authentication of sftp command in AIX 5.3

I need to send few files from AIX host to Windows host via sftp. Now this whole process needs to be automated starting from login to putting files in non-interactive mode.
Please help me out with the options to write such a shell script.
smartdev123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

smartdev123Author Commented:
Hi,

I did the following steps:

On server A logged in as Id x -

[/home/x]>ssh-keygen -t dsa
>chmod 700 .ssh
>cd .ssh
files generated-->
id_dsa
id_dsa.pub
>chmod 600 *
created file called authorized_keys
vi authorized_keys
chmod 600 authorized_keys

On server B logged in as Id y -

[/home/y]>ssh-keygen -t dsa
>chmod 700 .ssh
>cd .ssh
files generated-->
id_dsa
id_dsa.pub
>chmod 600 *
created file called authorized_keys
vi authorized_keys
chmod 600 authorized_keys
========================
Now, copied contents of id_dsa.pub of server A to authorized_keys of server B and vice versa.
Now, on server A I do:
[/home/x]>ssh server B
The authenticity of host 'server B (IP B)' can't be established.
RSA key fingerprint is 08:b5:98:d9:43:1a:af:dd:63:95:ce:7b:97:8c:14:4a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server B,IP B' (RSA) to the list of known hosts.
x@server B's password:

PLEASE ADVISE IF I MISSED ANY STEP . WHY IS IT STILL ASKING FOR PASSWORD?
ALSO, DO THE IDs ON BOTH THE MACHINES NEED TO BE THE SAME?
omarfaridCommented:
are you working on windows and aix unix systems ?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

smartdev123Author Commented:
No. I made this test between two AIX Unix systems. But in real time i will have to make it work between AIX and Windows.
omarfaridCommented:
try to generate keys with rsa option
smartdev123Author Commented:
tried that too..same result..:(

Isnt there any other way without involving key generations?
omarfaridCommented:
please steps in the link below:

http://waelchatila.com/2005/06/06/1118124232757.html

another key for ssh with no password

http://macnugget.org/projects/publickeys/
gheistCommented:
Maybe "copu oub to authorized" step made world-writable file due to less restrictive umask.
arober11Commented:
On both servers have you:
chmod 755 $HOME
chmod 700 $HOME.ssh
chmod 600 $HOME/.ssh/id_dsa

Checked the "/etc/ssh/sshd_config" to make sure it has the following enabled / defined?

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile     .ssh/authorized_keys

Done a: ls -la $HOME/.ssh/authorized_keys

Once you have AIX ot AIX running, can loop back to the sam host if you wish, have a play with Windows.

Which SSH / SFTP Deamon (SFTP server) are you going to be running at the Windows end, and have you enabled key based authentication (Not all support it)?

If the Windows sftp server dosen't support key based authentication, then you can either upgrade the server, or convert your sftp batch script  to an "expect" script, see:

http://www.perzl.org/aix/index.php?n=Main.Expect

And an example script:
#!/bin/sh
#Example 'expect' sftp script
#
EXPECT_DIR="/usr/bin"
LOG_DIR="/tmp"
LOG_FILE="expect.log"
SFTP_CMD_FILE="$HOME/test_sftp.bat"
SFTP_USER="a-user"
SFTP_HOST="localhost"
SFTP_PASS="xxxxxxx"

$EXPECT_DIR/expect 2>&1 > ${LOG_DIR}/${LOG_FILE} <<EOF
set timeout 1000000
spawn  /usr/bin/sftp -b $SFTP_CMD_FILE $SFTP_USER@$SFTP_HOST
log_file ${LOG_DIR}/${LOG_FILE}
expect "Connecting to $SFTP_HOST..." {
        expect {
        -re "^.*assword: " { send "$SFTP_PASS\r"
                             expect -re "^.assword: " { echo "ERROR SFTP password invalid\n"
                                                        exit 2  }
                             exit }
        eof { echo "WARNING: Connected without password\n"; exit }}
        echo "ERROR SFTP connection failed\n"
        exit 3 }
echo "ERROR SFTP initialization failed\n"
exit 1
EOF
SFTPEXIT=$?
echo "SFTP exit code: $SFTPEXIT"
exit $SFTPEXIT
smartdev123Author Commented:
Hi All,

Really apologize for the late reply..But, I am now able to ssh using keys without passwords.

Just a suggestion for those who are working on Unix..When you are copying your public key to the authorized_keys file of the target server, it should be pasted as a single line without any carraige returns. Preferrably use cat command rather than editors like vi etc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gheistCommented:
It is described in "man sshd"

AUTHORIZED_KEYS FILE FORMAT
     AuthorizedKeysFile specifies the file containing public keys for public
     key authentication; if none is specified, the default is
     ~/.ssh/authorized_keys.  Each line of the file contains one key (empty
     (because of the size of the public key encoding) up to a limit of 8 kilo-
     bytes, which permits DSA keys up to 8 kilobits and RSA keys up to 16
     kilobits.  You don't want to type them in; instead, copy the
     identity.pub, id_dsa.pub, or the id_rsa.pub file and edit it.
EE_AutoDeleterCommented:
I've requested that this question be deleted for the following reason:

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Not enough information to confirm an answer.

If you feel this question should be closed differently, post an objection and a moderator will read all objections and then close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Auto Deleter
gheistCommented:
#25024739 says even split between answers leading to it.
gheistCommented:
Also fair...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.