LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-21-2013, 03:23 AM   #1
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Rep: Reputation: Disabled
How to make sftp connection password based in Unix script


Hi Friends,

Im facing a issuse..

I was using sftp key based connection in script and worked fine.
Now i want to use password based sftp connection.

Question is How to make it happen through script without user interaction.

I tried below:
Quote:
sftp Username@Hostname
But this will wait untill someone manually enters the password.

please help me how i can make the connection through script!!

Thanks in advance for ur time !!!
 
Old 02-21-2013, 04:09 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
I wouldn't recommend using a passwd in a script, but if you insist, look at the expect tool http://linux.die.net/man/1/expect
 
1 members found this post helpful.
Old 02-21-2013, 06:59 AM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
ive done this with lftp, basically sftp on steroids kind of like the following:

Code:
LDIR=`pwd`
startdate="`date +%Y-%m-%d-%a-%H.%M.%S`"
username=XXXXXXXXX
password=XXXXXXXXX
backdir1=disk1/XXXXXXXXX
HOMEDIR="$HOME"
logname=${HOMEDIR}/logs/${startdate}-FTPBackup.log
url1=ftp.FOO.com

lftp1()

{
if [ "${NO_KILL}" != "true" ]
then
	lftp -e "set ftp:passive-mode on && cd ${backdir1} && put ${NEWTAR} && bye" -u ${username},${password} ${url1}
else
	lftp -e "set ftp:passive-mode on && cd ${backdir1} && put /tmp/${tarfilename}.tar.bz2 && bye" -u ${username},${password} ${url1}
fi

}
that should get you on the correct path.
 
Old 02-21-2013, 08:08 AM   #4
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
Like stated above this method is not recommended.
But you most likely can accomplish this like this:

Code:
sftp username:password@hostname
 
Old 02-22-2013, 12:55 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
Quote:
lftp, basically sftp on steroids
Its not using sftp, its using ftp ie NOT encrypted ...
 
Old 02-22-2013, 06:58 AM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by chrism01 View Post
Its not using sftp, its using ftp ie NOT encrypted ...
good to know, but there should be simular options for sftp as there are for lftp no?
 
Old 02-22-2013, 02:03 PM   #7
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
just read a small portion of the sftp man page:

Quote:
sftp is an interactive file transfer program, similar to ftp(1), which performs all operations over an encrypted ssh(1) transport. It may also use many features of ssh, such as public key authentication and compression. sftp connects and logs into the specified host, then enters an interactive command mode.
right there, there is no need to use a user/pw combination just setup the ssh keys and go from there.


http://linux.die.net/man/1/sftp
 
Old 02-22-2013, 02:09 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
He already used keys, now he wants to set it up to use a password. The solution has already been provided by chrism01, "expect".

An example:
Code:
#!/usr/bin/expect

set timeout -1

if { $argc == 1 } {
   set ip [lindex $argv 0]
} else {
   puts "Usage: $argv0 ip"
   exit 1
}

# Send files
spawn scp -p -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no file1 file2 file3 user@$ip:/dest/
expect *assword:
send "password\r"
expect eof

exit 0
Obviously you'd swap out "file{1,2,3}", "user", "password", and "/dest/" with the real ones.

Last edited by suicidaleggroll; 02-22-2013 at 02:10 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
script for sftp using password deepak_message Linux - Server 13 10-29-2012 05:46 AM
Help with a UNIX script: Need to grab information based on time from a file dba_guy Programming 13 05-28-2008 10:01 PM
Make aweb based tool to adminstrate Unix systems adam_blackice Programming 4 11-28-2006 03:53 AM
LXer: How to change Linux /UNIX system password-using a web based PHP script user interface LXer Syndicated Linux News 0 08-05-2006 08:33 PM
X won't make unix fontpath connection lugoteehalt Linux - Networking 0 05-13-2004 09:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:53 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