It's impossible to automic log into server using sftp in unix shell script with password authorization like what we can do with ftp below.
ftp -nv <<EOF
open ${FTP_HOST}
user ${FTP_USER}
${FTP_PASSWD}
binary
cd ${FTP_DIR}
put ${FTP_FILE_NAME}
dir
${FTP_FILE_NAME}
quit
EOF
But we have another solution for this, once it setup, it both conveneint and sercure. see following steps. tested on AIX.
On the client machine, type:
ssh-keygen -t rsa (or dsa, depending on the desired mode)
respond to the questions with CR
Make sure that the ssh daemon is running on the server.
On the client machine, CD to the .ssh directory in your home directory
and type:
scp id_rsa.pub <serverloginid>@<serverhostname>:id_rsa.pub
you will have to enter the password this time
Log onto the server and CD to your home directory. (The "id_rsa.pub"
file should be visible). Check to see if a .ssh directory exists; if
not, create one and type:
cat id_rsa.pub >> .ssh/authorized_keys
You can delete the id_rsa.pub file from the server (or move it into the
.ssh folder).
That should set up the automatic login authentication.
Reference
- http://unix.ittoolbox.com/groups/technical-functional/ibm-aix-l/sftp-auto-login-500638#
- OpenSSH 密钥管理
- Getting started with SSH
2006-6-14 Update
If access to the remote system is still denied you should check the permissions of the following files on it:- the home directory itself
- the ~/.ssh directory
- the ~/.ssh/authorized_keys file
The permissions should allow writing only by you (the owner). This example shows the most relaxed permissions you could use.
hrothgar% cd
hrothgar% ls -ld . .ssh .ssh/authorized_keys
drwxr-xr-x 36 kim kim 4096 Jul 25 02:24 .
drwxr-xr-x 2 kim kim 512 Apr 10 02:30 .ssh
-rw-r--r-- 1 kim kim 1674 Apr 10 02:29 .ssh/authorized_keys
- 文章信息
- 版权声明: 本文可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息。
- 原文出处: http://www.aiview.com/
- 写于: 2006-06-13 [Edit]
- 作者: Alex (email &msn)

- 标签 Tags: sftp (2)


