I still have to enter the password when I want to auto login w/o having to do any command line entry. This code works but I don't want to have to enter the password at the command line. After manning ssh I still am not sure what settings I need to change. Please help. Thanks!
<<<output>>>
$ sh file_exists.ksh
clport@dwebapp1's password:
file exists
<<<code>>>
#!usr/bin/sh
hostname=dwebapp1
login_name=clport
# password=
if [ -n `ssh -l $login_name@$hostname 'ls test/testfile.txt 2>/dev/null'` ]; then
echo file exists
else
echo "file doesn't exist";
fi
As syndex points out, you need to configure ssh keys correctly for passwordless (i.e. key-based) authentication to work. There are plenty of documents detailing this on the net.
You might also want to look into the Net::SFTP Perl module.
I set up my keys using ssh-keygen ; copied the key to .ssh/authorized_keys on the remote server. Logged out, logged in and exicuted the script at the beginning of this post and I still was forced to enter command line password. ARGH! I don't understand what I am doint wrong.
The authenticity of host 'dwebapp1 (57.2.20.1)' can't be established.
. key fingerprint is RSA.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no'.
yes
Warning: Permanently added 'dwebapp1,57.2.20.1' (RSA) to the list of known hosts.
clport@dwebapp1's password:
file exists
$ ksh file_exists.ksh
clport@dwebapp1's password: