LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-07-2021, 09:51 AM   #1
GioMBG
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Rep: Reputation: Disabled
sshpass howto


hi All,
hoping to find You all well.

I need to use sshpass in an sh script,
please : avoid recommending to use a public key : I know what it is I always use but this is not the case thanks !

so normally if I run this sh script I need to insert manually the password :

Code:
#!/usr/bin/sh
sftp -oPort=22 username@host.example.com<<EOF
cd /data
put /myfile.txt /log.txt
bye
exit
EOF
what I want is to use sshpass to put the passwd directly into the script OR at the best in an external file.

Avoiding to post all the fake examples copied and re-copied and re-copied again around the web that don't want to work...

Can I kindly have an help in how to use sshpass in my scirpt.sh ?
thanks
Gio
 
Old 04-07-2021, 09:55 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,223

Rep: Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445
SSH_ASKPASS is probably your friend.
 
Old 04-07-2021, 09:55 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,510
Blog Entries: 3

Rep: Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762
It looks like you are trying to use batch mode, but missing the -b option. Batch mode will not work without SSH keys (or SSH certificates instead) for authentication. So keys are not so much a recommendation as they are a requirement.

Code:
cat << EOF | sftp -i somekey -b - -P 22 username@host.example.com
cd /data
put /myfile.txt /log.txt
EOF
See "man sftp" for the details.
 
  


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
sshpass dont make the command running postcd Linux - General 3 05-16-2014 08:51 AM
[SOLVED] scp using sshpass har_85 Programming 5 03-04-2014 05:38 AM
LXer: sshpass command : Non-interactive Password Authentication with SSH LXer Syndicated Linux News 0 08-27-2013 03:40 PM
sshpass issue in executing commands in sftp Mode. pradeepdee6 Linux - Newbie 7 04-17-2013 09:18 AM
LXer: sshpass - Non-interactive ssh password authentication LXer Syndicated Linux News 0 05-04-2008 04:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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