1

scp like ssh has an option -i. In SSH that's documented as -i identity_file, and I have a file which works with ssh user@dest -i my.key to log in to a device without a password. SCP documents the same option as

-i identity_file Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to ssh(1).

(emphasis mine). This documentation is clearly wrong, because scp my.file user@dest:/home/user/ -i my.key fails with

my.key: Not a directory

No, it's indeed not a directory. Clearly scp is not directly passing the argument to ssh, it does a check first, and that check in scp is probably the wrong way around (give an error if the argument is a directory)

Anyway, since scp -i is broken, what can I use instead? SCP version is from Debian 10, man page is dated 2018, no --version option available

2
  • 1
    this might not be the scp you are looking for, can you add result of command -v scp, whereis scp and which scp ? do you still have an error using /usr/bin/scp -i my.key ... ? – Archemar Feb 23 at 15:11
  • @Archemar: /usr/bin/scp, right beside /usr/bin/ssh. – MSalters Feb 23 at 16:00
18

You need to specify the options before the sources and target:

scp -i my.key my.file user@dest:/home/user/

See the synopsis in man scp:

scp [-346ABCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] [-J destination] [-l limit] [-o ssh_option] [-P port] [-S program] source ... target

The error you’re seeing is the result of scp interpreting my.file, user@dest:/home/user, and -i as sources, and my.key as the target: it checks that the target is a directory, and fails because it’s a file.

3
  • Works. Weirdly enough ssh has the same documented requirement, but it does accept a trailing -i identity_file option. – MSalters Feb 23 at 16:40
  • 2
    So it does, as long as you don’t specify a command! I can see how that would be confusing... – Stephen Kitt Feb 23 at 16:46
  • Personally, I blame the GNU people for this one. Most GNU tools just let you do that, even though POSIX is pretty explicit about putting options before operands. – Kevin Feb 24 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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