Skip to content

Instantly share code, notes, and snippets.

@rigobertocontreras
Created April 29, 2015 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rigobertocontreras/863dc63fec35e54dadb1 to your computer and use it in GitHub Desktop.
Save rigobertocontreras/863dc63fec35e54dadb1 to your computer and use it in GitHub Desktop.
OpenSSH is particular with how keys are stored and used. Do the following:
1) Create and ensure your ~/.ssh directory has the correct permissions:
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh
$ ls -ld ~/.ssh
drwx------ 2 username group 4096 Jun 10 19:47 /Users/username/.ssh
2) Copy the private key (in your case the .pem file) to the ~/.ssh directory and set the appropriate permissions:
$ cp ~/Downloads/filename.pem ~/.ssh/filename.pem
$ chmod 600 ~/.ssh/filename.pem
3) Since you are using OS X make sure Finder didn't set any unnecessary extended attributes and remove them:
$ xattr -l ~/.ssh/filename.pem
$ xattr -d <attr_name> ~/.ssh/filename.pem
4) Now you can try using the key:
$ ssh -i ~/.ssh/filename.pem username@remote.hostname.com
5) Once you have verified this work you can use the ~/.ssh/config file to make connecting to the remote host easier, rather than having to manually specify the identity file to use. For example:
Host remote.hostname.com
User username
IdentityFile ~/.ssh/filename.pem
From this point forward you can just run ssh remote.hostname.com to connect to your remote server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment