Skip to content

Instantly share code, notes, and snippets.

@cognivator
Last active March 28, 2024 19:32
Show Gist options
  • Select an option

  • Save cognivator/91e4f8cbf41cf7fe1b9a31f4d0ec56c7 to your computer and use it in GitHub Desktop.

Select an option

Save cognivator/91e4f8cbf41cf7fe1b9a31f4d0ec56c7 to your computer and use it in GitHub Desktop.

Revisions

  1. cognivator revised this gist Mar 28, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion macos_multiple_SSH_keys.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ There are plenty of references for generating and using SSH keys on MacOS. Googl

    ### Solution
    The nuggets of goodness I found describe how to properly use `~/.ssh/config` - ([here](https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9), [here](https://medium.nextlevelswift.com/creating-two-ssh-keys-on-mac-for-two-different-github-accounts-b2456734e8f1), [here](https://pratapsharma.io/github-miltiple-key), [
    here](https://gist.github.com/jmcaldera/e445ff878c81e16d0c19b4049f009703)... +[many more](https://www.google.com/search?q=macos+ssh+github+multiple+keys)). The key bit of information to make everything work is to actually _**use**_ the resulting `Host` aliases!
    here](https://gist.github.com/jmcaldera/e445ff878c81e16d0c19b4049f009703)... +[many more](https://www.google.com/search?q=macos+ssh+github+multiple+keys)). The key is actually _**using**_ the resulting `Host` aliases!

    Go figure, huh? :facepalm:

  2. cognivator revised this gist Mar 28, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions macos_multiple_SSH_keys.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    ### Situation
    There are plenty of references for generating and using SSH keys on MacOS. Google for answers and they're everywhere. What is harder to do is use multiple SSH keys, especially for the same host, e.g. GitHub. I had multiple SSH keys, and a `~/.ssh/config` file, but certain of the credentials weren't being found.
    There are plenty of references for generating and using SSH keys on MacOS. Google for answers and they're everywhere. What is less obvious is how to use multiple SSH keys, especially for the same host, e.g. GitHub. I had multiple SSH keys and a `~/.ssh/config` file, but certain of the credentials weren't being found.

    ### Solution
    The nuggets of goodness I found describe how to properly use `~/.ssh/config` - ([here](https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9), [here](https://medium.nextlevelswift.com/creating-two-ssh-keys-on-mac-for-two-different-github-accounts-b2456734e8f1), [here](https://pratapsharma.io/github-miltiple-key), [
    here](https://gist.github.com/jmcaldera/e445ff878c81e16d0c19b4049f009703)...). The key bit of information to make everything work is to actually _**use**_ the resulting `Host` aliases!
    here](https://gist.github.com/jmcaldera/e445ff878c81e16d0c19b4049f009703)... +[many more](https://www.google.com/search?q=macos+ssh+github+multiple+keys)). The key bit of information to make everything work is to actually _**use**_ the resulting `Host` aliases!

    Go figure, huh?
    Go figure, huh? :facepalm:

    ### Example: Github - SourceTree
    In concrete terms, and skipping all the SSH generation tasks — references abound — the key insight in code is...
    @@ -27,5 +27,5 @@ Then anywhere you would normally reference the url host directly... don't. Use t
    - NO: `git@`**github.com**`:username/repository.git`
    - YES: `git@`**github-alias-x**`:username/repository.git`

    It's magical.
    It's magical. :magic_wand:

  3. cognivator created this gist Mar 28, 2024.
    31 changes: 31 additions & 0 deletions macos_multiple_SSH_keys.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    ### Situation
    There are plenty of references for generating and using SSH keys on MacOS. Google for answers and they're everywhere. What is harder to do is use multiple SSH keys, especially for the same host, e.g. GitHub. I had multiple SSH keys, and a `~/.ssh/config` file, but certain of the credentials weren't being found.

    ### Solution
    The nuggets of goodness I found describe how to properly use `~/.ssh/config` - ([here](https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9), [here](https://medium.nextlevelswift.com/creating-two-ssh-keys-on-mac-for-two-different-github-accounts-b2456734e8f1), [here](https://pratapsharma.io/github-miltiple-key), [
    here](https://gist.github.com/jmcaldera/e445ff878c81e16d0c19b4049f009703)...). The key bit of information to make everything work is to actually _**use**_ the resulting `Host` aliases!

    Go figure, huh?

    ### Example: Github - SourceTree
    In concrete terms, and skipping all the SSH generation tasks — references abound — the key insight in code is...

    Add the host-key mappings to `~/.ssh/config`,
    ```
    Host github-alias-1
    HostName github.com
    ...
    IdentifyFile ~/.ssh/key1
    Host github-alias-2
    HostName github.com
    ...
    IdentifyFile ~/.ssh/key2
    ```

    Then anywhere you would normally reference the url host directly... don't. Use the `Host` alias from the config file instead,
    - NO: `git@`**github.com**`:username/repository.git`
    - YES: `git@`**github-alias-x**`:username/repository.git`

    It's magical.