Solved

SFTP - passing a password from within a script

Posted on 2002-07-01
7
23,070 Views
Last Modified: 2010-08-05
I just about have everything working with SFTP.  I tested SFTP using a batch file to pass it the commands and it works great.  The problem I have though is it prompts me to put a password before it starts reading the file and processing the commands.

Here is the syntax I use from the command line:

sftp -b /path/genPluginBatch webuser@webhost

I tried putting the password as the first line in the batch file, genPluginBatch, but it sees this as a bad command.  Any idea how I would pass the password from within a script?

Just so you know I also tried the following from within the script:

sftp wsadmin@uscscdev7 webuser@webhost <<EOF
<password>
cd /opt/WebSphere/AppServer/config
put plugin-cfg.xml
bye
EOF


Thanks,

Lisa
0
Comment
Question by:lphillips120898
7 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 7123310
You can try the -n option:

sftp -n wsadmin@uscscdev7 webuser@webhost <<EOF
...etc...
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 150 total points
ID: 7124044
sh does not allow to read password from STDIN (batch file, here document, or whatever) for obvious reason.
You need to setup sh with a RSA or DSA key which has a blank password
AFAIK sftp has no -i option to specify the key-file, so you're forced to use the default ones, ~/.ssh/identity for example.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7124046
oops, typo:
please substitute all words sh by ssh
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:PeterMac
ID: 7126856
Havn't tried with SFTP, but following works with most FTP systems. Needs -n on command line to allow manual login. Insert at start of batch file :-

user "USERNAME"
"PASSWD"

Alternatively should be possible to setup SFTP to run with "anonymous" access permitted. Will not then require entry of username, password at all.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7127074
SFTP is a very different beast from FTP.  Ahoffman's comments are right-on.
0
 

Expert Comment

by:SoHo
ID: 7319941
why don't you use ssh keys.
0
 

Expert Comment

by:SoHo
ID: 7319945
ahoffman already gave that answer, duh.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now