Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. Oanh Nguyen revised this gist Feb 23, 2016. 1 changed file with 39 additions and 21 deletions.
    60 changes: 39 additions & 21 deletions using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -1,50 +1,68 @@

    ## Problem
    I have a GitHub account, it is *oanhnn*, but at office, I couldn't use my personal GitHub account. I have to use an other GitHub account, eg *supermen*.
    I want use both two accounts on same computer (use without typing password each times, when git push or pull).
    I have two Github accounts: *oanhnn* (personal) and *superman* (for work).
    I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

    ## Solution
    Using ssh keys and ssh config file to create an alias host and use multiple GitHub accounts
    Use ssh keys and define host aliases in ssh config file (each alias for an account).

    ## How to?
    1. [Make key pair for each accounts](https://help.github.com/articles/generating-a-new-ssh-key/) and [add it to GitHub accounts](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/).
    2. Make ssh configure file (`~/.ssh/config`) like:
    1. [Generate ssh key pairs for accounts](https://help.github.com/articles/generating-a-new-ssh-key/) and [add them to GitHub accounts](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/).
    2. Edit/Create ssh config file (`~/.ssh/config`):

    ```
    ```conf
    # Default github account: oanhnn
    Host github.com
    HostName github.com
    IdentityFile ~/.ssh/oanhnn_private_key
    IdentitiesOnly yes
    # Other github account: supermen
    Host github-supermen
    # Other github account: superman
    Host github-superman
    HostName github.com
    IdentityFile ~/.ssh/supermen_private_key
    IdentityFile ~/.ssh/superman_private_key
    IdentitiesOnly yes
    ```

    3. [Added ssh key to your agent](https://help.github.com/articles/adding-a-new-ssh-key-to-the-ssh-agent/) by command:
    3. [Add ssh private keys to your agent](https://help.github.com/articles/adding-a-new-ssh-key-to-the-ssh-agent/):

    ```
    ```shell
    $ ssh-add ~/.ssh/oanhnn_private_key
    $ ssh-add ~/.ssh/supermen_private_key
    $ ssh-add ~/.ssh/superman_private_key
    ```

    4. Check that repo recognizes keys.
    4. Test your connection

    ```
    ```shell
    $ ssh -T git@github.com
    $ ssh -T git@github-supermen
    $ ssh -T git@github-superman
    ```

    5. Clone projects
    With each command, you may see this kind of warning, type `yes`:

    ```shell
    The authenticity of host 'github.com (192.30.252.1)' can't be established.
    RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:
    Are you sure you want to continue connecting (yes/no)?
    ```
    $ git clone git@github-supermen:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "supermen@org2.com"
    $ git config user.name "Super Men"
    If everything is OK, you will see these messages:
    ```shell
    Hi oanhnn! You've successfully authenticated, but GitHub does not provide shell access.
    ```

    ```shell
    Hi superman! You've successfully authenticated, but GitHub does not provide shell access.
    ```
    5. Now all are set, just clone your repositories
    ```shell
    $ git clone git@github-superman:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "superman@org2.com"
    $ git config user.name "Super Man"
    ```
    Done! Have goodluck!
    Done! Goodluck!
  2. Oanh Nguyen revised this gist Feb 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ I have a GitHub account, it is *oanhnn*, but at office, I couldn't use my person
    I want use both two accounts on same computer (use without typing password each times, when git push or pull).

    ## Solution
    Using ssh keys and ssh configure file to alias host and using multiple GitHub accounts
    Using ssh keys and ssh config file to create an alias host and use multiple GitHub accounts

    ## How to?
    1. [Make key pair for each accounts](https://help.github.com/articles/generating-a-new-ssh-key/) and [add it to GitHub accounts](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/).
  3. Oanh Nguyen revised this gist Feb 1, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -14,11 +14,13 @@ Using ssh keys and ssh configure file to alias host and using multiple GitHub ac
    Host github.com
    HostName github.com
    IdentityFile ~/.ssh/oanhnn_private_key
    IdentitiesOnly yes
    # Other github account: supermen
    Host github-supermen
    HostName github.com
    IdentityFile ~/.ssh/supermen_private_key
    IdentitiesOnly yes
    ```

    3. [Added ssh key to your agent](https://help.github.com/articles/adding-a-new-ssh-key-to-the-ssh-agent/) by command:
  4. Oanh Nguyen revised this gist Feb 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ Using ssh keys and ssh configure file to alias host and using multiple GitHub ac
    $ git clone git@github-supermen:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "supermen@org2.com"
    $ git config user.name "Supper Men"
    $ git config user.name "Super Men"
    ```


  5. Oanh Nguyen revised this gist Feb 1, 2016. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,46 @@
    ## Problem
    I have a github account, it is *oanhnn*, but when i join a private project in company, i have to use an other github account, eg *suppermen*.
    I want using two accounts without typing password each times, when git push or pull.
    I have a GitHub account, it is *oanhnn*, but at office, I couldn't use my personal GitHub account. I have to use an other GitHub account, eg *supermen*.
    I want use both two accounts on same computer (use without typing password each times, when git push or pull).

    ## Solution
    Using ssh keys and ssh configure file to alias host and using multiple github accounts
    Using ssh keys and ssh configure file to alias host and using multiple GitHub accounts

    ## How to?
    1. Make key pair for each accounts and add it to github accounts.
    1. [Make key pair for each accounts](https://help.github.com/articles/generating-a-new-ssh-key/) and [add it to GitHub accounts](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/).
    2. Make ssh configure file (`~/.ssh/config`) like:

    ```
    # Default github account: oanhnn
    Host github.com
    HostName github.com
    IdentityFile ~/.ssh/oanhnn_key
    IdentityFile ~/.ssh/oanhnn_private_key
    # Other github account: suppermen
    Host github-suppermen
    # Other github account: supermen
    Host github-supermen
    HostName github.com
    IdentityFile ~/.ssh/suppermen_key
    IdentityFile ~/.ssh/supermen_private_key
    ```

    3. Added ssh key to your agent by command:
    3. [Added ssh key to your agent](https://help.github.com/articles/adding-a-new-ssh-key-to-the-ssh-agent/) by command:

    ```
    $ ssh-add ~/.ssh/oanhnn_key
    $ ssh-add ~/.ssh/suppermen_key
    $ ssh-add ~/.ssh/oanhnn_private_key
    $ ssh-add ~/.ssh/supermen_private_key
    ```

    4. Check that repo recognizes keys.

    ```
    $ ssh -T git@github.com
    $ ssh -T git@github-suppermen
    $ ssh -T git@github-supermen
    ```

    5. Clone projects

    ```
    $ git clone git@github-suppermen:org2/project2.git /path/to/project2
    $ git clone git@github-supermen:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "suppermen@org2.com"
    $ git config user.email "supermen@org2.com"
    $ git config user.name "Supper Men"
    ```

  6. Oanh Nguyen revised this gist Jan 26, 2016. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ Using ssh keys and ssh configure file to alias host and using multiple github ac
    ## How to?
    1. Make key pair for each accounts and add it to github accounts.
    2. Make ssh configure file (`~/.ssh/config`) like:

    ```
    # Default github account: oanhnn
    Host github.com
    @@ -19,23 +20,29 @@ Using ssh keys and ssh configure file to alias host and using multiple github ac
    HostName github.com
    IdentityFile ~/.ssh/suppermen_key
    ```

    3. Added ssh key to your agent by command:

    ```
    $ ssh-add ~/.ssh/oanhnn_key
    $ ssh-add ~/.ssh/suppermen_key
    ```

    4. Check that repo recognizes keys.

    ```
    $ ssh -T git@github.com
    $ ssh -T git@github-suppermen
    ```

    5. Clone projects

    ```
    $ git clone git@github-suppermen:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "suppermen@org2.com"
    $ git config user.name "Supper Men"
    ```


    Done! Have goodluck!
  7. Oanh Nguyen created this gist Jan 26, 2016.
    41 changes: 41 additions & 0 deletions using-multiple-github-accounts-with-ssh-keys.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    ## Problem
    I have a github account, it is *oanhnn*, but when i join a private project in company, i have to use an other github account, eg *suppermen*.
    I want using two accounts without typing password each times, when git push or pull.

    ## Solution
    Using ssh keys and ssh configure file to alias host and using multiple github accounts

    ## How to?
    1. Make key pair for each accounts and add it to github accounts.
    2. Make ssh configure file (`~/.ssh/config`) like:
    ```
    # Default github account: oanhnn
    Host github.com
    HostName github.com
    IdentityFile ~/.ssh/oanhnn_key
    # Other github account: suppermen
    Host github-suppermen
    HostName github.com
    IdentityFile ~/.ssh/suppermen_key
    ```
    3. Added ssh key to your agent by command:
    ```
    $ ssh-add ~/.ssh/oanhnn_key
    $ ssh-add ~/.ssh/suppermen_key
    ```
    4. Check that repo recognizes keys.
    ```
    $ ssh -T git@github.com
    $ ssh -T git@github-suppermen
    ```
    5. Clone projects
    ```
    $ git clone git@github-suppermen:org2/project2.git /path/to/project2
    $ cd /path/to/project2
    $ git config user.email "suppermen@org2.com"
    $ git config user.name "Supper Men"
    ```


    Done! Have goodluck!