I have a text of a private key file. I want to connect via ssh to other node, yet the gateway I am in does not provide me with file system access. How to pass a text representation of key and not a file with it to ssh client?

  • 3
    Is using ssh-agent and then ForwardAgent=yes to forward the keys contained therein possible?
    – thrig
    Commented Jun 10, 2016 at 16:09
  • 2
    Do you ssh to that gateway? And if so, does it accept forwarding of authentication agent (ssh -A gateway)? Commented Jun 10, 2016 at 16:11
  • 2
    You don't even have write access to /tmp? What can you do? Can you still run arbitrary shell commands? Commented Jun 10, 2016 at 16:12
  • @ Stéphane Chazelas: I was able to run arbitrary shell commands and had write access to /tmp and I was allowed to set chmod on created in /temp file. This solved my problem, thank you!
    – DuckQueen
    Commented Jun 10, 2016 at 19:24
  • 1
    Bad idea -- anyone who can look at the process table on the gateway will be able to read the command - and thus, the key. Commented Jun 13, 2016 at 13:19

1 Answer 1


It sounds like you don't really need to store your key on the bastion, but really just need to connect to something on the other side. If that's true, and provided it's not blocked by the SSH server you're connecting to, you should be able to use OpenSSH's ProxyCommand. In the following example, bastion is the external host you're using to reach into remote network.

ssh -o ProxyCommand "ssh bastion.example.com -W %h:%p" internal.example.com

Since that's not exactly easy typing, I'd recommend putting it into your ${HOME}/.ssh/config like this:

Host internal.example.com
     User username
     Hostname internal.example.com
     ProxyCommand ssh bastion.example.com -W %h:%p

Hostnames may be substituted with IP addresses if necessary.

You must log in to answer this question.

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