4

I need to run some commands in parallel including SCP. For this I'm using GNU Parallel. The problem is I don't know how to pass the password to SCP. This is a line similar to the one I'm running:

ls 2011_* | parallel scp {} user@domain

And if ls finds 3 files, scp ask 3 times for password at the same time and I can only input the password to the last process to prompt for it.

I temporarily solved this issue connecting using a public key, but this won't be an option in the future due to company policies. I read the SCP man pages and I couldn't find an option, but I'm quite confident that Parallel should have an option to allow me to input the password.

Somebody knows a way to solve this?

EDIT: I want to know if there is a way I can tell parallel the password so it can give it to scp each time it asks for it. Maybe with something like this:

ls 2011_* | parallel scp {} user@domain < file_with_password.txt

But specifying that the redirection of STDIN is for scp and not for ls or parallel.

Topo
  • 4,783
  • 9
  • 48
  • 70

2 Answers2

4

You will want to look at ssh-agent: The benefit of having a passphrase protected certificate with the convenience of typing your passphrase only once.

GNU Parallel >= 20220322 supports this syntax if you have sshpass installed:

parallel -S user:password@server ...
Ole Tange
  • 31,768
  • 5
  • 86
  • 104
2
parallel sshpass -p $PASS scp -P $PORT -rp {} ~/to_dir ::: $ADDRESS:~/from_dir/*
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Jordan
  • 455
  • 6
  • 21
  • 1
    EDIT: parallel sshpass -p $PASS scp -P $PORT -rp {} ~/to_dir ::: $ADDRESS:~/from_dir/* – Jordan Mar 18 '16 at 21:03
  • 3
    Welcome to Stack Overflow! While this code may answer the question, it would be better to include some _context_, explaining _how_ it works and _when_ to use it. Code-only answers are not useful in the long run. Also, you can [edit] your answer, no need to add comments to indicate it. I've edited it for you to add your change and fix code formatting (four spaces for code highlighting). – Benjamin W. Mar 18 '16 at 21:11