I have a laptop and a raspberry pi acting as a storage server. I'd like to know how to download a file without any user interaction other than running the program. I read through the man page, and there doesn't seem to be a way to specify a password on the scp or sftp command line.


1 Answer 1


ssh and its cousin sftp, because they are written to be secure (it's right there in the name after all) by design to not allow for passwords to be provided on the commandline, as that's a very easy way to leak your passwords into a plaintext log file such as the shell's history.

If you want to enable headless, yet still authenticated, file transfer, create a public/private keypair with ssh-keygen but provide a blank passphrase. You can then use that keypair to authenticate for your sftp transaction once the public key has been installed on the remote host.

If you really want to use sftp you will also have to send the commands to sftp that you'd ordinarily enter on its interactive prompt. It would be simpler to use scp:

$ scp [email protected] /path/to/my/file ./file
  • scp has been deprecated. An LWN article discusses why, and what can be done. Apr 26, 2021 at 18:18
  • That article is discussing a proposal for deprecating scp; I have not seen that it actually has been. Indeed, that article is discussing at its conclusion an in-place stand-in for scp that will still DTRT with current invocations while acting as a shim for sftp.
    – DopeGhoti
    Apr 26, 2021 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .