6

I can't make working a scp command with sshpass when using a custom identity file and a custom port. When activate verbose mode (sshpass -v) I can see scp (or something) is asking for the private key passphrase.

The scp alone is working fine, when I enter the passphrase:

scp -P 30001 -i /home/debian/sshkey-withpass_rsa file.txt debian@server.net:/home/debian/
Enter passphrase for key '/home/debian/sshkey-withpass_rsa':
file.txt 100% ...

But it does not work with sshpass (version 1.09). There is no error, it just hang... If I active verbose (sshpass -v) I can see the "Enter passphrase for key..." message.

The password is the first line of file /home/debian/sshkey-withpass_rsa.txt.

sshpass -f /home/debian/sshkey-withpass_rsa.txt scp -P 30001 -i /home/debian/sshkey-withpass_rsa file.txt debian@server.net:/home/debian/

Any idea ? Thanks

Cyrille37
  • 325

2 Answers2

9

After reading the manpage several times, I found the -P option to set the password prompt. By default, sshpass searches for the string assword:. However, when using key-based authentification, the password prompt is Enter passphrase for key so it doesn't contain assword which is why it fails.

So to make it work with key authentification, we have to set a custom value for the prompt with -P:

sshpass -P "passphrase for key" -f thepasswordfile.txt scp ...
muru
  • 207,228
Cyrille37
  • 325
3

Good that you solved the problem. But it's good to know that in such cases (or even more complicated ones) you can always resort to expect (of course you need to install it first). Use script like this (not tested):

#!/usr/bin/expect
spawn scp -P 30001 -i /home/debian/sshkey-withpass_rsa file.txt debian@server.net:/home/debian/
expect "passphrase for key"
send "yourpassword\r"
raj
  • 11,409