Skip to content

Instantly share code, notes, and snippets.

@inakiarroyo
Last active December 6, 2024 09:55
Show Gist options
  • Select an option

  • Save inakiarroyo/c3748b514e18cc85193ef545f03513c8 to your computer and use it in GitHub Desktop.

Select an option

Save inakiarroyo/c3748b514e18cc85193ef545f03513c8 to your computer and use it in GitHub Desktop.

Revisions

  1. inakiarroyo revised this gist Jan 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -101,7 +101,7 @@ ssh-add -l
    ```
    3. If necessary, add your new key to the list:
    ```
    ssh-add ~/.ssh/personalid
    ssh-add -K ~/.ssh/personalid
    ----
    $ ssh-add ~/.ssh/personalid
    Enter passphrase for /Users/username/.ssh/personalid:
  2. inakiarroyo revised this gist Oct 1, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -115,7 +115,8 @@ ssh-add -l
    If for any reason your keys are not re-added automatically to the ssh-agent after a reboot, follow this post:
    https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain

    *Solution*
    **Solution**

    Apple updated its [Technical Notes](https://developer.apple.com/library/content/technotes/tn2449/_index.html#//apple_ref/doc/uid/DTS40017589) to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.

    In `~/.ssh` create `config` file with the following content:
  3. inakiarroyo revised this gist Oct 1, 2019. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -115,16 +115,16 @@ ssh-add -l
    If for any reason your keys are not re-added automatically to the ssh-agent after a reboot, follow this post:
    https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain

    ### Solution
    Apple updated its [Technical Notes](https://developer.apple.com/library/content/technotes/tn2449/_index.html#//apple_ref/doc/uid/DTS40017589) to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.
    *Solution*
    Apple updated its [Technical Notes](https://developer.apple.com/library/content/technotes/tn2449/_index.html#//apple_ref/doc/uid/DTS40017589) to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.

    In `~/.ssh` create `config` file with the following content:
    In `~/.ssh` create `config` file with the following content:

    ```bash
    Host * (asterisk for all hosts or add specific host)
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile <key> (e.g. ~/.ssh/userKey)
    ```bash
    Host * (asterisk for all hosts or add specific host)
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile <key> (e.g. ~/.ssh/userKey)
    ```

    ## Step 4. Repositories
  4. inakiarroyo revised this gist Oct 1, 2019. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -115,17 +115,17 @@ ssh-add -l
    If for any reason your keys are not re-added automatically to the ssh-agent after a reboot, follow this post:
    https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain

    ### Solution 1 (recommended)
    Apple updated its [Technical Notes](https://developer.apple.com/library/content/technotes/tn2449/_index.html#//apple_ref/doc/uid/DTS40017589) to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.
    ### Solution
    Apple updated its [Technical Notes](https://developer.apple.com/library/content/technotes/tn2449/_index.html#//apple_ref/doc/uid/DTS40017589) to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.

    In `~/.ssh` create `config` file with the following content:
    In `~/.ssh` create `config` file with the following content:

    ```bash
    Host * (asterisk for all hosts or add specific host)
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile <key> (e.g. ~/.ssh/userKey)
    ```
    ```bash
    Host * (asterisk for all hosts or add specific host)
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile <key> (e.g. ~/.ssh/userKey)
    ```

    ## Step 4. Repositories
    ### Clone git repository
  5. inakiarroyo revised this gist Oct 1, 2019. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -111,6 +111,21 @@ Identity added: /Users/username/.ssh/personalid
    ```
    ssh-add -l
    ```
    5. Adds keys automatically
    If for any reason your keys are not re-added automatically to the ssh-agent after a reboot, follow this post:
    https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain

    ### Solution 1 (recommended)
    Apple updated its [Technical Notes](https://developer.apple.com/library/content/technotes/tn2449/_index.html#//apple_ref/doc/uid/DTS40017589) to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.

    In `~/.ssh` create `config` file with the following content:

    ```bash
    Host * (asterisk for all hosts or add specific host)
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile <key> (e.g. ~/.ssh/userKey)
    ```

    ## Step 4. Repositories
    ### Clone git repository
  6. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -66,8 +66,13 @@ IdentityFile ~/.ssh/identity
    Host github-workid
    HostName github.org
    IdentityFile ~/.ssh/workid
    Host bitbucket-personalid
    HostName bitbucket.org
    IdentityFile ~/.ssh/personalid
    Host github-personalid
    HostName github.org
    HostName github.com
    IdentityFile ~/.ssh/personalid
    ```
    ### Load each key into appropiate Host account
  7. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ Enter passphrase (empty for no passphrase):
    ```

    You can create multiple SSH identities with this three ssh- commands:

    | SSh Command | Purpose |
    |-------------|:-------------:|
    | ssh-keygen | Create keys pairs |
  8. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ Enter passphrase (empty for no passphrase):

    You can create multiple SSH identities with this three ssh- commands:
    | SSh Command | Purpose |
    | ------------- | ------------- |
    |-------------|:-------------:|
    | ssh-keygen | Create keys pairs |
    | ssh-agent | Agent for proving keys to remote servers. The agent holds loaded keys in memory |
    | ass-add | Loads a private key into the agent |
  9. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,8 @@ Enter passphrase (empty for no passphrase):
    ```

    You can create multiple SSH identities with this three ssh- commands:
    | SSh Command | Purpose |
    | ------------- |:-------------:|
    | SSh Command | Purpose |
    | ------------- | ------------- |
    | ssh-keygen | Create keys pairs |
    | ssh-agent | Agent for proving keys to remote servers. The agent holds loaded keys in memory |
    | ass-add | Loads a private key into the agent |
  10. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ ssh-keygen -t rsa -f ~/.ssh/personalid -C "personalid"
    '-C' requests compression of all data.
    ```
    ```
    $ ssh-keygen -f ~/.ssh/personalid -C "personalid"
    $ ssh-keygen -t rsa -f ~/.ssh/personalid -C "personalid"
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
  11. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -89,7 +89,10 @@ $ ps | grep ssh-agent
    ```
    - If not run `ssh-agent`.
    - If there is more than 1 process running use `kill PID` command to stop each of them. Then restart a single instance.
    2. List the currently loaded keys: `ssh-add -l`
    2. List the currently loaded keys:
    ```
    ssh-add -l
    ```
    3. If necessary, add your new key to the list:
    ```
    ssh-add ~/.ssh/personalid
    @@ -98,13 +101,21 @@ $ ssh-add ~/.ssh/personalid
    Enter passphrase for /Users/username/.ssh/personalid:
    Identity added: /Users/username/.ssh/personalid
    ```
    4. List the keys again to verify the add was successful: `ssh-add -l`
    4. List the keys again to verify the add was successful:
    ```
    ssh-add -l
    ```

    ## Step 4. Repositories
    ### Clone git repository
    1. Using the default key: `git clone git@github.com:username/project.git`
    2. Using a specific key: ` git clone git@personalid:username/project.git` (`git@personalid:iarroyo5/project.git`)

    ## Step 5. known_hosts
    Remove entries from known_hosts:
    ```
    ssh-keygen -R hostname
    ```



  12. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -77,6 +77,8 @@ cat ~/.ssh/id_rsa.pub
    ```
    pbcopy < ~/.ssh/id_rsa.pub
    ```

    ## Step 3. ssh-agent
    ### Ensure the ssh-agent is running and loaded with your keys
    1. Check if the process is already running:
    ```
    @@ -98,8 +100,8 @@ Identity added: /Users/username/.ssh/personalid
    ```
    4. List the keys again to verify the add was successful: `ssh-add -l`

    ## Step 4. Repositories
    ### Clone git repository

    1. Using the default key: `git clone git@github.com:username/project.git`
    2. Using a specific key: ` git clone git@personalid:username/project.git` (`git@personalid:iarroyo5/project.git`)

  13. inakiarroyo revised this gist Apr 22, 2017. 1 changed file with 108 additions and 1 deletion.
    109 changes: 108 additions & 1 deletion multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,108 @@
    # Multiple SSH keys with ~/.ssh/config
    # Working with multiple SSH keys
    ## Step 1. Ensure you have an SSH client installed
    ```
    ssh -V
    ls -a ~/.ssh
    ```
    ## Step 2. Set up your identity
    You can create a default identity
    ```
    $ ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/username/.ssh/id_rsa):
    ----
    Enter passphrase (empty for no passphrase):
    ```

    You can create multiple SSH identities with this three ssh- commands:
    | SSh Command | Purpose |
    | ------------- |:-------------:|
    | ssh-keygen | Create keys pairs |
    | ssh-agent | Agent for proving keys to remote servers. The agent holds loaded keys in memory |
    | ass-add | Loads a private key into the agent |

    ### Create multiple identities
    ```
    ssh-keygen -t rsa -f ~/.ssh/personalid -C "personalid"
    '-t' force pseudo-terminal allocation.
    '-f' requests ssh to go to background just before command execution.
    '-C' requests compression of all data.
    ```
    ```
    $ ssh-keygen -f ~/.ssh/personalid -C "personalid"
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /Users/username/.ssh/personalid.
    Your public key has been saved in /Users/username/.ssh/personalid.pub.
    The key fingerprint is:
    7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 personalid
    The key's randomart image is:
    +--[ RSA 2048]----+
    | |
    | |
    | .|
    | Eo|
    | . S . ..|
    | . . o . ... .|
    | . = = ..o o |
    | . o X ... . .|
    | .ooB.o .. |
    +-----------------+
    ```
    ### Create a SSH config file
    When you have multiple identity files, creating a SSH config file allows you to create aliases for your various identities.
    The format for the alias entries used is:
    ```
    Host alias
    HostName github.org
    IdentityFile ~/.ssh/identity
    ```
    1. Edit the `~/.ssh/config` file
    2. Add an alias for each identity combination
    ```
    Host github-workid
    HostName github.org
    IdentityFile ~/.ssh/workid
    Host github-personalid
    HostName github.org
    IdentityFile ~/.ssh/personalid
    ```
    ### Load each key into appropiate Host account
    Copy your specific public key (`.pub`)
    ```
    cat ~/.ssh/id_rsa.pub
    ```
    ```
    pbcopy < ~/.ssh/id_rsa.pub
    ```
    ### Ensure the ssh-agent is running and loaded with your keys
    1. Check if the process is already running:
    ```
    ps | grep ssh-agent
    ----
    $ ps | grep ssh-agent
    4013 ttys001 0:00.00 grep ssh-agent
    ```
    - If not run `ssh-agent`.
    - If there is more than 1 process running use `kill PID` command to stop each of them. Then restart a single instance.
    2. List the currently loaded keys: `ssh-add -l`
    3. If necessary, add your new key to the list:
    ```
    ssh-add ~/.ssh/personalid
    ----
    $ ssh-add ~/.ssh/personalid
    Enter passphrase for /Users/username/.ssh/personalid:
    Identity added: /Users/username/.ssh/personalid
    ```
    4. List the keys again to verify the add was successful: `ssh-add -l`

    ### Clone git repository

    1. Using the default key: `git clone git@github.com:username/project.git`
    2. Using a specific key: ` git clone git@personalid:username/project.git` (`git@personalid:iarroyo5/project.git`)




  14. inakiarroyo created this gist Apr 22, 2017.
    1 change: 1 addition & 0 deletions multiple_ssh_setting.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Multiple SSH keys with ~/.ssh/config