I've made a huge mistake, or at least I think I did: I've "catted" my private SSH key

cat ~/.ssh/id_rsa

I'm now afraid that I've created a security hole, allowing other users to see my private key by looking at bash/scrollback history or using other methods. So, my questions:

  1. Did I really compromise the security of my SSH keypair?
  2. Are there 'sufficiently secure' ways of patching it, excluding the obvious (and most secure) way of creating a new keypair?

(NOTE: i'm the only user of the machine so I'm actually not that concerned in my specific case, but I thought this would be an interesting question.)

  • user1686's answer is germane. But if you're worried about others gaining access to your private key in some way (roaming phones and you like to look at your key?), then put a passphrase on that private key and use ssh-agent. Google how to use ssh-agent. To put a passphrase on your key: ssh-keygen -f path_to_key -p.
    – fbicknel
    Jan 14 at 14:56

1 Answer 1


If you did this in private, there's no problem. Think about it – you only displayed on screen the exact same data that is already stored on your harddisk anyway. And if anyone could access your scrollback or your history, they could just as well read the id_rsa file directly.

  • Besides, your shell's history – even if it was readable to other users (which it isn't) – only contains commands, not their output. So all it'll have is a line with cat ~/.ssh/id_rsa in it.

  • The scrollback history, for most terminals, is stored entirely in memory. (libvte-based terminals sometimes use a backing file in /tmp, but that's either a tmpfs or is located in the same disk as your ~/.ssh, anyway...) So it becomes irrelevant once you close the terminal. And either way it is only accessible to you, of course.

  • And very often, the private key itself is encrypted with a passphrase and is unusable unless you decrypt it when ssh asks to.

Unless, of course, you did this in the presence of high-resolution security cameras, or even outright allowed someone to snap a photo of your terminal window. In that case, someone could retype the key from photos, and the only thing protecting it would be the encryption passphrase.

You must log in to answer this question.

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