LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   sshpass howto (https://www.linuxquestions.org/questions/linux-software-2/sshpass-howto-4175693276/)

GioMBG 04-07-2021 09:51 AM

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

pan64 04-07-2021 09:55 AM

SSH_ASKPASS is probably your friend.

Turbocapitalist 04-07-2021 09:55 AM

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.


All times are GMT -5. The time now is 02:08 AM.