Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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/
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.