1

I have 3 Linux system.

System_A System_B System_C

I want to copy a file from "System_B" to "System_C", while being logged in from system System_A.

Below code copies the file from "System_A" to "System_C" (as I'm running this while logged in from "System A")

sshpass -p "pass123" scp /u01/File_A.txt oracle@$ServerIP_C:/u01/File_C.txt

Also, below code does what I want.i.e. copies file from "System_B" to "System_C", while being logged in from system System_A.

sshpass -p "pass123" scp oracle@$ServerIP_B/u01/File_B.txt oracle@$ServerIP_C:/u01/File_C.txt

But in above code it asks for 1 password as I'm only passing 1 password through sshpass instead of 2.

How can I pass the 2nd password through sshpass here so that it doesn't prompt me for password.

I have tried below codes:

 sshpass -p "pass123" sshpass -p "pass123" scp oracle@IP_B:/tmp/File_B.txt oracle@IP_C:/tmp/File_C.txt
This throws error: Conflicting password source

sshpass -p "pass123" scp oracle@IP_B:/tmp/File_B.txt sshpass -p "pass123" oracle@IP_C:/tmp/File_C.txt
Promted for 1 Password
0

You should consider using SSH keys. With a key you can connect to a computer without having to enter a password. It is also recommended as an alternative on the sshpass man page.

  • I totally agree with you on key pair, however i have limited access to the changes which i can make to set up Key pair, That is the reason why I want this somehow to work using sshpass. – Rahul Aug 22 '18 at 17:12
  • You can try to pass two lines as argument to the -p option separated by a newline. You can also try to invoke sshpass twice, like sshpass -p "pass1" sshpass -p "pass2" scp .... – RalfFriedl Aug 22 '18 at 17:14
  • Could you please give command for "You can try to pass two lines as argument to the -p option separated by a newline."... The later didn't worked, I have edited the question with output of later command. – Rahul Aug 22 '18 at 17:33
  • I just looked at the source, it will not work with two passwords, I just looked at the source. But you might try the program expect. – RalfFriedl Aug 22 '18 at 18:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.