How to pass password to scp?
You can script it with a tool like expect (there are handy bindings too, like Pexpect for Python).
want to pass the password from the shell script for the scp command for transferring the file from one server to another
You can use sshpass for that.
sshpass -p password scp -r root@$source_host:/$source_path root@$destination_host:/$destination_path
Pass password with sshpass to both servers when scp copying from one server to another
This is not possible.
According to scp
manual:
-3
Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this option disables the progress meter and selects batch mode for the second host, since scp cannot ask for passwords or passphrases for both hosts.
And according to ssh_config
manual:
BatchMode
If set to
yes
, user interaction such as password prompts and host key confirmation requests will be disabled. This option is useful in scripts and other batch jobs where no user is present to interact withssh(1)
. The argument must beyes
orno
(the default).
How to pass in the password in scp using Java ssh JSch and jcabi-ssh
Automating an execution of an interactive command is a sign of a bad design. Anyway...
The scp
will prompt your for a password in an interactive session/terminal only. For security reasons, it won't read the password from a plain standard input.
So you have to enable an interactive session/terminal.
In JSch, you do that by calling .setPty
:
channel.setPty(true);
channel.connect();
Similar question: Use JSch sudo example and Channel.setPty for running sudo command on remote host.
Another approach is using expect
or sshpass
tools: How to pass password to scp?
Related Topics
Finding Number Is Even/Odd in Assembly
Why Should Eval Be Avoided in Bash, and What Should I Use Instead
How to Set the Environmental Variable Ld_Library_Path in Linux
How to Get Overall Cpu Usage (E.G. 57%) on Linux
How to Install Latest Version of Git on Centos 8.X/7.X/6.X
How to Replace a String in Multiple Files in Linux Command Line
How to Set the Gopath Environment Variable on Ubuntu? What File Must I Edit
Connection Refused to Mongodb Errno 111
How Can a Process Intercept Stdout and Stderr of Another Process on Linux
Compiling C++ on Remote Linux Machine - "Clock Skew Detected" Warning
Multiline Bash Command in Jenkins Pipeline
How to Permanently Set $Path on Linux/Unix
Filter Log File Entries Based on Date Range
How to Link to a Specific Glibc Version
The 'Eval' Command in Bash and Its Typical Uses
Retrieve Cpu Usage and Memory Usage of a Single Process on Linux