Skip to content

Instantly share code, notes, and snippets.

@eMdOS
Last active July 17, 2017 22:38
Show Gist options
  • Save eMdOS/986c1dae12feb20a3d4f372eb55ef665 to your computer and use it in GitHub Desktop.
Save eMdOS/986c1dae12feb20a3d4f372eb55ef665 to your computer and use it in GitHub Desktop.
SSH set up

SSH Keys

Generating a new SSH key

  1. Create a ssh key:

    ssh-keygen -t rsa -b 4096 -C "<email>"
  2. Enter the name and the passphrase.

SSH Config

  1. Creating a config file (~/.ssh/):

    touch config
  2. Editing the config file:

    nano config
  3. Adding into config file:

    # Personal account
    Host personal.github.com
    	HostName github.com
    	AddKeysToAgent yes
    	UseKeychain yes # KeyChain (for macOS)
    	PreferredAuthentications publickey
     	IdentityFile ~/.ssh/<personal_key>
    
    # Enterprise account
    Host enterprise.github.com
     	HostName github.com
     	AddKeysToAgent yes
     	UseKeychain yes # KeyChain (for macOS)
    	PreferredAuthentications publickey
    	IdentityFile ~/.ssh/<enterprise_key>

Adding your SSH key to the ssh-agent

  1. Start the ssh-agent in the background:

    eval "$(ssh-agent -s)"
  2. Add your SSH private key to the ssh-agent:

    ssh-add -K ~/.ssh/<ssh_filename>
    1. On macOS, ssh-agent will "forget" this key, once it gets restarted during reboots. But you can import your SSH keys into Keychain using this command:

      /usr/bin/ssh-add -K ~/.ssh/<ssh_filename>

Adding a new SSH key to your repository account

  1. Copy the SSH key to your clipboard:

    pbcopy < ~/.ssh/<ssh_filename>.pub

Testing your SSH connections

ssh -T git@<config_host>.github.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment