Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)

I need to transfer the log file to the remote host using sftp from the Linux host. I have been provided credentials for this same from my operations group. However, since I don't have control over the other host, I cannot generate and share the RSA keys with some other host.

Is there any way to run an sftp command (with a username/password provided) from inside a Bash script through the cron job?

1 Answer

0 votes
by (36.8k points)
edited by

You have some options other than using the public key authentication:

  1. Use keychain
  2. Use the sshpass (less secured but probably that meets your requirement)
  3. Use except (least secured and more coding needed)

If you decide to give sshpass the chance here is the working script snippet to do so:

export SSHPASS=your-password-here

sshpass -e sftp -oBatchMode=no -b - sftp-user@remote-host << !

   cd incoming

   put your-log-file.log

   bye

!

Want to be a Linux expert? Come and join this Linux course

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 4, 2021 in Linux by blackindya (18.4k points)

Browse Categories

...