Passing a private key to scp from the command line instead of a file [closed]
Is there a way to pass the contents of a private key directly to the scp
command instead of having to copy it to a file and pointing at it via the -i /path/to/key.pem
option?
So instead of doing:
scp -i key.pem source target
Can I do something like the following?
scp -i '-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAMIIEowIBAA...\n' source target
Of course I tried this and it doesn't work but maybe this can be achieved with some BASH piping, output redirection, or something like that.
The reason I need to do this is because I can't store the keys in the filesystem (it's a very long and boring story) and this command will need to be executed millions and millions of times with a different key each time so the extra disk i/o will be significant in our results.
If you can't disclose any more information we really can't help you: Questions on Server Fault need to provide sufficient context for us to intelligently analyze the problem, and this one doesn't.
What I can tell you definitively is that "passing the key on the command line" is a Bad Idea: if you do this you inherit all the problems discussed in this question which basically mean anyone on the machine can see your private key. (This is why the ssh
, scp
, and sftp
commands don't let you do it.)
Consider using ssh-agent
to handle your keys instead -- there are some additional implications here, but you can basically store your keys on the filesystem, load them into the agent, and then allow the agent to pass the keys along to the client for authentication purposes (which should solve, or at least reduce your performance issues).
If ssh-agent
is not suitable for your needs you're pretty much down to hacking and recompiling the SSH client to support what you want in some way.