Setting Up SSH Keys for Multiple Accounts
If you have multiple user accounts on Pagoda Box, each account must have it's own unique SSH Key(s). Doing this does require a little extra setup, but is still pretty simple to do. This doc will walk you through setting up SSH keys for multiple accounts. After reading it, you should be familiar with:
- Creating multiple SSH keys
- Configuring Git to use multiple SSH keys
- Enjoying the awesomeness of multiple Pagoda Box accounts
Before You Get Started
SSH keys are necessary when using git to push and pull code to and from Pagoda Box or connect to a services. If one of your accounts doesn't need this kind of access, you may not need to go through the process of generating multiple keys and configuring Git & SSH to properly use them.
Also, many times the desired workflow that comes from separate Pagoda Box accounts can often be achieved through the much simpler process of adding team members to an app.
This Doc is Command Line Based
The instructions in this doc are all run from the command line. You can accomplish the same steps through the vast number of GIT/SSH GUIs out there, but whether or not you use those is up to you. For this doc, only the command line tools will be used.
Generate & Add Your SSH Keys
SSH keys can be generated by cd'ing into
~/.ssh and running the following command for each key:
Generate a New SSH Key Pair Terminal
$ ssh-keygen -t rsa -C "firstname.lastname@example.org"
When specifying the name of the keys, be sure they're different so one will not overwrite the other. Enter a passphrase if you'd like or just press Enter to continue on.
You can name your keys whatever you'd like. For this example, we'll use the following names:
Once the keys are generated, add the new identities to the SSH authentication agent by running the following:
Add the New Key Identities Terminal
$ ssh-add ~/.ssh/id_rsa_user1 $ ssh-add ~/.ssh/id_rsa_user2
To make sure the identities were added successfully, run:
Checking Your Saved Key Identities Terminal
$ ssh-add -l
Modify Your SSH Config
In order for SSH to know which key pair to use when, you must modify the
config file in your
~/.ssh directory. If the
config file does not already exist, you'll need to create one:
Creating an SSH Config File Terminal
$ cd ~/.ssh $ touch config
Open up your
config file and add details for each of your SSH keys, similar to the following:
Modifying Your SSH Config File SSH
#pagoda box account 1 Host pagodabox-user1 HostName git.pagodabox.io User git IdentityFile ~/.ssh/id_rsa_user1 #pagoda box account 2 Host pagodabox-user2 HostName git.pagodabox.io User git IdentityFile ~/.ssh/id_rsa_user2
The "Host" values,
pagodabox-user2 are aliases for the ssh configuration settings. What those aliases are is completely up to you, but they will be used in your git workflow.
Add Your Keys to Your Pagoda Box Accounts
Before your apps will be able to push and pull to and from Pagoda Box, you'll need to add your keys to their respective accounts. This is covered in the Setting Up SSH Keys doc.
Modify the Git Config for Each Repo
Now that SSH has been configured and your SSH keys have been added to your Pagoda Box accounts, you need to specify which user each of your repos should use. This is done by modifying the git config for each repo. Cd into each of your repos and run the following:
Modifying Your Git Config Terminal
$ git config user.name "pagodabox-user1" $ git config user.email "email@example.com" -- OR -- $ git config user.name "pagodabox-user2" $ git config user.email "firstname.lastname@example.org"
Adjustments to Your Git Workflow
Git and SSH keys are tied together, so any adjustment to your SSH keys will affect your git workflow. When using multiple SSH keys, Git needs to know which key to use when. Modifying the Git config, as explained above, is one way to tell Git which SSH key to use, but what if you're cloning a repo and don't have access to the Git config yet. In this case, you need to tell Git which SSH key to use through the use of your SSH config aliases.
Cloning a Repo with a Specific Account Terminal
# Pattern $ git clone git@[ssh_alias]:[clone_path] # Example $ git clone git@pagodabox-user1:apps/demo-app
The same applies if you want to push to an app using a specific account. This method only needs to be used if you have not modified the Git config of the repo to tell it which SSH alias to use.
Pushing to an App Using a Specific Account Terminal
# Pattern $ git push git@[ssh_alias]:[remote_name] # Example $ git push git@pagodabox-user1:pagoda
SSH Keys, Users, & Collaboration
SSH keys are tied to individual Pagoda Box user accounts. If you try to push to an app with a specific SSH key and that key is tied to a user who is not a collaborator on the app, the push will fail.
Table of Contents
If you have any questions, suggestions, or corrections, let us know.