LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2008, 11:29 AM   #1
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Rep: Reputation: 15
sftp script help


All,

I have a script i need to sftp to anoother server, and sftp is the only thing i can use. Im to script username and password but still keep getting prompted for the password. Can someone tell me what needs to be changed?

Thanks!

#!/bin/sh

HOST='IP of dest svr'
USER='userid'
PASSWD='passwd'

sftp ${HOST} << EOF
user {$USER} {$PASSWD}
lcd /home/userid
put test.txt
exit
 
Old 10-05-2008, 02:02 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
According to the sftp manpage (http://www.eos.ncsu.edu/remoteaccess/man/sftp.html), there is no user interactive command. You will need to find another way to enter the password.

It's probably using PAM to get the password, which tends to read its input directly from the terminal bypassing the standard input stream, so tricks like "echo $PASS | sftp ..." won't work. You could fool it by messing around with pseudo-ttys, but I've always found them rather hard to work with.

A much easier solution would be to set up public key authentication, as described here: http://sial.org/howto/openssh/publickey-auth/ (nb: the sftp program actually uses ssh as its transport layer, hence the talk of ssh in the howto).
 
Old 10-05-2008, 02:57 PM   #3
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
But in order for this to work, doesn't sshd_config on the remote server have to have a option set to allow for passwordless authentification? I on the server im trying to run sftp from i did "ssh-keyget -t rsa and dsa" and cat'ted them into an authorized_keys file on the server and then scp'd that auth_keys file to the remote server and then tried to sftp the file over i am trying to transfer and still got prompted for the password.

So is my mistake in how i generated the keys and moved the auth_keys file to the remote server or is it the option in sshd_config? If its the sshd_config file then im SOL cause i dont have access to it because it isnt my server and its locked down like a drum.

Thanks for responding so quickly!
 
Old 10-05-2008, 07:06 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, you shouldn't really put usernames/passwds in scripts, as this is a definite security risk.
That being said, you can use the 'expect' utility to automate the passwd handling.
Possibly also look at ssh-agent : http://mah.everybody.org/docs/ssh
 
Old 10-05-2008, 08:29 PM   #5
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Yea i know i shouldnt but this is at the clients request because it is a pretty harmless server so if it did get hacked, no biggie. So anyone know how to get around the usernam and passwd issue with sftp?

Thanks
 
Old 10-06-2008, 01:58 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
authorised keys ?
 
Old 10-06-2008, 09:17 AM   #7
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Read my post just above your first post, i mentioned that already. Not working.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sftp script help imkornhulio Programming 11 09-17-2008 11:23 AM
SFTP Script chnlinux Linux - General 1 09-28-2007 05:33 PM
SFTP Script chnlinux Linux - Newbie 2 09-28-2007 03:53 PM
Reg the sftp script chnlinux Linux - Newbie 2 09-27-2007 04:27 PM
sftp script error JeRrYmAn Linux - Networking 1 11-27-2003 07:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration