LinuxQuestions.org
Help answer threads with 0 replies.
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 04-12-2013, 11:13 AM   #1
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Rep: Reputation: Disabled
sshpass issue in executing commands in sftp Mode.


I need to connect to a Unix server with sftp password based authentication.
I was able to achieve this through sshpass package.

I use AIX machine and bash,ksh,sh,

The problem im facing is im not able to automate the commands to be executed in sftp password based authentication.

Below are few things i tried.
was able to connect with this
Quote:
export SSHPASS=abc@123
sshpass -e sftp sftpuser@sftpserver
tried to pass commands using -t. but failed
Quote:
export SSHPASS=abc@123
sshpass -e sftp sftpuser@sftpserver -t "cd /base_dir/sub_dir;get *.txt;bye"
ERROR: usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config
Below code i didnt get error and didnt get file also
Quote:
export SSHPASS=abc@123
sshpass -e sftp -oBatchMode=no -b - sftpuser@sftpserver << !
cd /base_dir/sub_dir
get *.txt
bye
!
Please help me how can i execute the commands inside the sftp mode with a password based authentication.
 
Old 04-12-2013, 12:58 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
after a fast read you will need to setup ssh keys between the two systems. sftp uses ssh connection over port 21. therefore you can use standard ssh key pairs to authenticate without entering a password. this makes life simple for scripting.

Code:
[~/.ssh] $ ssh-key-gen -t rsa -b 4096
and follow the directions on the screen. as you will be using this in a script do not give it a passphrase or any response, just hit the enter key. then you will want to copy that *.pub file to the new server and set it up properly. if you are going from linux to linux that is simple with
Code:
ssh-copy-id -i /path/to/id_rsa.pub foo@remote_IP
 
1 members found this post helpful.
Old 04-15-2013, 01:48 AM   #3
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Thanks lleb,

But im looking for password based authentication with sftp :-(
Please help me with password based authentication than key based..

my effort for password based authentication did not give me results.

Thanks very much for your time.!!
 
Old 04-15-2013, 08:52 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Re post #2: sftp uses port 22 as its part of the ssh pkg (see also scp).
You may be thinking of FTP+TLS, a completely different thing.
 
Old 04-15-2013, 11:25 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,919

Rep: Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689
Quote:
Originally Posted by pradeepdee6 View Post
I need to connect to a Unix server with sftp password based authentication. I was able to achieve this through sshpass package. I use AIX machine and bash,ksh,sh, The problem im facing is im not able to automate the commands to be executed in sftp password based authentication.

Below are few things i tried.
was able to connect with this

tried to pass commands using -t. but failed

Below code i didnt get error and didnt get file also
Please help me how can i execute the commands inside the sftp mode with a password based authentication.
Almost the same thing you posted before, here:
http://www.linuxquestions.org/questi...pt-4175451074/

You were directed to the "expect" command before, which will do what you want. And did you bother trying to read the man page on sshpass?
http://linux.die.net/man/1/sshpass

Pay particular attention to the "-p" flag, which is where you provide the password, and looking for examples on how to use sshpass in a script provides lots as well:
http://www.cyberciti.biz/faq/noninte...word-provider/
 
Old 04-15-2013, 01:05 PM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by chrism01 View Post
Re post #2: sftp uses port 22 as its part of the ssh pkg (see also scp).
You may be thinking of FTP+TLS, a completely different thing.
ahh yes, thank you.

to the OP, the expect script posted above is what you would need for password based authentication vs key based. you are far more secure with key based as with the expect script your password will be in raw text format that anyone can read.
 
Old 04-17-2013, 04:38 AM   #7
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Hi TBone, chrism01

thanks for your time.

TBone, i was not allowed to use spawn command (expect), so i opted to go with sshpass.
I went through the man pages for sshpass. It no where mentions about passing commands when we establish connection.

So please can you direct me if sshpass really has any option to execute get commands in sftp mode.

appriciate your time..!!
 
Old 04-17-2013, 10:18 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,919

Rep: Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689
Quote:
Originally Posted by pradeepdee6 View Post
Hi TBone, chrism01
TBone, i was not allowed to use spawn command (expect), so i opted to go with sshpass.
Why are you 'not allowed' to use a standard Linux utility?
Quote:
I went through the man pages for sshpass. It no where mentions about passing commands when we establish connection. So please can you direct me if sshpass really has any option to execute get commands in sftp mode.
Right...because again, sshpass is for password authentication. You use it WITH ssh, which is where you pass the command. sshpass gets you logged in, ssh does the work. If you looked at the link I sent you, it has an example of use with the ssh command. So try this: replace the ssh command with the sftp command.

Again, if you just did a keyswap, you wouldn't need ANY of this, and it would be more secure. If you use expect, it would also be trivial to do. Also, since this is the second time you've posted the same question, have you bothered to try to look this up? Putting "how to use sshpass with sftp" into Google gives LOTS of examples.

Since you want to be spoon-fed an answer:
Code:
sshpass -p 'password' sftp -oBatchMode=no -b - sftp-user@remote-host << !
   cd incoming
   put your-log-file.log
   bye
Please show some effort. The man pages for sshpass and sftp are fairly clear, and examples are easy to find if you tried.

Last edited by TB0ne; 04-17-2013 at 10:22 AM.
 
1 members found this post helpful.
  


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
[SOLVED] executing commands in invisible mode dinakumar12 Linux - Newbie 12 04-15-2010 01:27 AM
How commands are executing ? gsiva Linux - Server 1 07-21-2009 09:48 AM
Executing commands at a specified time Siva4Linux Linux - Wireless Networking 7 02-21-2007 06:49 AM
Executing commands in Konsole... meteotrade Linux - General 5 10-20-2003 07:34 PM
Executing commands on startup viciousfish Linux - General 5 06-28-2002 03:15 PM


All times are GMT -5. The time now is 11:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration