PDF download Download Article PDF download Download Article

"Deploy keys" in GitHub allow your server to connect directly to your GitHub repository. When your server is connected, you can push builds directly from your repository to your server, which can cut down on your work. If your server needs access to multiple repositories, you can create a machine user to manage the access.

Part 1
Part 1 of 3:

Generating a Key

PDF download Download Article
  1. The terminal program on your computer allows you to remotely access your server. If you're using a Linux or Mac computer, you'll be using the built-in Terminal program. If you're using Windows, you'll need to install a program like Cygwin or GitBash.
    • Linux - Press Ctrl + Alt + T or search for "terminal."
    • Mac - You can find the Terminal program in the Utilities folder.
    • Windows - You can download Cygwin from cygwin.com , or GitBash from git-scm.com/downloads .
  2. You'll be generating the deploy key on your server so that it can access your GitHub repository. To do this, you'll need to log into your server, either remotely through your terminal or locally on the server.
    • In your terminal program, type ssh username @ hostname to log in. Enter your password if prompted. [1]
    Advertisement
  3. The following command will create a new key with your GitHub email address as the label:
    • ssh-keygen -t rsa -b 4096 -C " email@example.com "
    • An SSH key is a encrypted key pair that authenticates your identity. In this case, you'll be assigning the key to your GitHub repository, allowing it to identify your server.
  4. Enter / Return when prompted to select a location. This will save the key to the default location, which is the .ssh directory in your User directory.
  5. This adds an additional layer of security to your key, as unknown users will need to enter the passphrase before the key will work.
    • You'll be prompted to confirm the passphrase when creating it.
  6. Once the key has been created, you'll need to add it to your repository. To do so, you'll need to copy the contents of the key. The following command will copy the contents of the key to your clipboard: [2]
    • Linux - xclip -sel clip < ~/.ssh/id_rsa.pub . You may need to run sudo apt-get install xclip first.
    • Windows - clip < ~/.ssh/id_rsa.pub
    • Mac - pbcopy < ~/.ssh/id_rsa.pub
  7. Advertisement
Part 2
Part 2 of 3:

Adding the Key to a Repository

PDF download Download Article
  1. Make sure you log in with an account that can access the repository.
  2. This will open your GitHub profile page.
  3. This will display all of your repositories.
  4. This will grant your server access to the repository to automatically deploy builds.
  5. This will open your repository settings.
  6. This will display the deploy keys that are currently assigned to the repository.
  7. A text field for the key will appear.
  8. Click the field and press Command / Ctrl + V to paste the copied deploy key into the field.
    • If you want the server to have write access to the repository, check the "Allow write access" box.
  9. This will allow your server to access the repository and deploy builds from it. [3]
  10. Advertisement
Part 3
Part 3 of 3:

Creating a Machine User

PDF download Download Article
  1. A "machine user" is an automated user that can access multiple repositories. This is useful if your server needs access to multiple repositories, since deploy keys only grant access to a single repository.
    • You can create a new user by clicking the "Sign up" button on the GitHub homepage and following the prompts.
  2. Follow the steps in the first section to generate a key on your server and copy it to your clipboard.
  3. You'll be assigning the newly-created key to this user.
  4. This will open the account settings for the machine user.
  5. This will display the keys currently assigned to the user.
  6. This will allow you to enter the SSH key.
  7. This will add the SSH key to the machine user's profile, allowing it to access your server. [4]
  8. You can find your repositories in the "Repositories" tab on your Profile page.
  9. This will display the repository settings.
  10. This will allow you to add collaborators to the repository. By adding your machine user as a collaborator, it will be able to push builds from your repository to your server.
  11. The machine user will be given read/write access to the repository. [5]
  12. Advertisement

Expert Q&A

Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      About This Article

      Thanks to all authors for creating a page that has been read 52,009 times.

      Is this article up to date?

      Advertisement