Skip to content

Instantly share code, notes, and snippets.

@karancraze
Last active August 1, 2018 14:44
Show Gist options
  • Save karancraze/dbd1f1bd37adfad89590c6a90ed357b3 to your computer and use it in GitHub Desktop.
Save karancraze/dbd1f1bd37adfad89590c6a90ed357b3 to your computer and use it in GitHub Desktop.
My ssh cheat sheet

SSH Cheat Sheet

To create ssh key if does not exist

ssh-keygen

And then follow steps on the screen.

List all the keys which exist in ssh-agent

ssh-add -l

If you already have the key

First start the ssh-agent

eval $(ssh-agent)

(you will get output as - Agent pid XXXX)

Add the path of the key to the agent

ssh-add ~/.ssh/<private_key_file>

To add persistant key in Mac

(Note: In Mac ssh-add is not persistant i.e. the keys will be lost if you restart or ssh-agent is terminated/restarted)
  1. By adding ssh key passphrase to your mac key chain

ssh-add -K ~/.ssh/<private_key_file>

(Then letting your ssh-agent know to load the key from Mac's keychain everytime)
  1. Create config file at ~/.shh by navigating to .ssh/ folder and using

nano config

  1. Type this code in config file and save it. Change id_rsa to the name of your key if using custom key

Host *
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa

You can use this command to load keys in your keychain manually

ssh-add -A

Permissions on the ssh key files

  • .ssh directory - chmod 700 - (drwx------)
  • public key (.pub file) - chmod 644 - (-rw-r--r--)
  • private key (id_rsa) - chmod 600 - (-rw-------)
  • home directory - chmod 755 - (drwxr-xr-x) - (should not be writeable by the group or others)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment