I have dotfiles saved in a public github repo, which include the path to my aws keys, which seems like a terrible thing waiting to happen.

So it's like this:

function superssh { ssh user@something -i /file/path/to/keys;}

What's a better way of doing this that improves my security?


Hiding your key in an unusual place is not making it any safer. If you undertake basic good practice for key management there's really no need to do anything extra.

Your private key needs to be kept 'secret', this primarily achieved by encrypting it. You should use a strong passphrase to encrypt your key. On your system(s) openssh enforces additional restrictions in that it will not use a private key that is accessible by anyone other than it's owner.

Your public key is just that, public, you can give it to anyone.

  • If I encrypt the private key with a strong passphrase, won't I need to type that passphrase every time I need to use (unencrypt) the private key? I'm new to this, so where else can I learn about basic good practices for key management? – John Dec 6 '15 at 21:45
  • Yes, or you can use ssh-agent. – Iain Dec 6 '15 at 21:48

If someone has enough access to your box to harvest your keys, it's game over anyway. Don't worry about it.


If you want to do it this way, then you could use environment variables:

export KEY_FOO=/path/to/key/foo.pem
export KEY_BAR=/path/to/key/bar.pem

Put those exports in your .bash_profile or .bashrc or whatever bash init config you have. Then you can do something like this in other dot files.

function superssh { ssh user@something -i $KEY_FOO; }
  • This is not secure, don't try to "hide" it. – cristi Dec 7 '15 at 19:57
  • Putting a filename in an environment variable isn't really safe or unsafe. Insofar as the key itself, make sure it is encrypted, as others have said, and make sure the file owner, group, and permissions are correct. – thoughtarray Dec 7 '15 at 20:00

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.