How to Use Deploy Keys on Github
Part 1 of 3:
Generating New Keys
- Open the terminal program on your computer. 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.
- Log into your server using your terminal program. 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]
- Enter the command to generate the SSH key. 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.
- Press .↵ 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.
- Create a passphrase. 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.
- Copy the SSH key contents to your clipboard. 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
Part 2 of 3:
Adding the Key to Your Repository
- Log into the GitHub website. Make sure you log in with an account that can access the repository.
- Click your profile image in the upper-right corner and select "Your profile." This will open your GitHub profile page.
- Click the "Repositories" tab. This will display all of your repositories.
- Select the repository you want to add the key to. This will grant your server access to the repository to automatically deploy builds.
- Click the "Settings" tab at the top of the screen. This will open your repository settings.
- Click the "Deploy keys" button in the left menu. This will display the deploy keys that are currently assigned to the repository.
- Click the "Add deploy key" button. A text field for the key will appear.
- Paste the copied deploy key into the field. 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.
- Click "Add key" to add your deploy key. This will allow your server to access the repository and deploy builds from it.[3]
Part 3 of 3:
Creating a Machine User
- Create a dedicated GitHub account for the machine user. 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.
- Generate an SSH key on your server. Follow the steps in the first section to generate a key on your server and copy it to your clipboard.
- Sign into the GitHub website with the new machine user account. You'll be assigning the newly-created key to this user.
- Click the machine user's profile picture and select "Settings." This will open the account settings for the machine user.
- Click the "SSH and GPG keys" option in the left menu. This will display the keys currently assigned to the user.
- Click the "New SSH key" button. This will allow you to enter the SSH key.
- Paste the key and click "Add SSH key." This will add the SSH key to the machine user's profile, allowing it to access your server.[4]
- Open the first repository you want to give the machine user access to. You can find your repositories in the "Repositories" tab on your Profile page.
- Click the "Settings" tab on the repository page. This will display the repository settings.
- Click the "Collaborators" option in the left menu. 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.
- Enter the machine user's name and click "Add collaborator." The machine user will be given read/write access to the repository.[5]
5 ★ | 1 Vote
You should read it
May be interested
- GitHub Models launches, allowing developers to find and test AI models for freegithub has officially announced github models, a new service that allows developers to find and test ai models for free.
- How to Download a GitHub Folderthis wikihow teaches you how to download a github folder by downloading an entire repository. github allows you to download a repo locally to your computer with just a few simple steps. please note that downloading a specific folder from...
- 82% of code on GitHub is copying existing filesthat's the result of a recent study by researchers from the university of california, irvine, microsoft research, czech technical and northeastern.
- GitHub is under strong phishing attack, users pay attention to account securitygithub - the world's largest open source software repository, is now the target of a phishing attack campaign.
- GitHub Copilot is now available for free in VS Codegithub, the most popular platform for the global developer community, has officially surpassed 150 million members.
- GitHub's machine learning tool can detect vulnerabilities in codegithub's tool will help eliminate common security holes before the code is put into the final stage.
- GitHub free all features for usersdevelopers can use all the core features of github without paying for it.
- Git and GitHub - Using Git the right way to maximize your worktoday's lesson we will learn the basics of git and github
- GitHub launches 'Copilot', an AI that can code with yougithub has just officially launched a new ai programming tool called copilot. this tool will accompany programmers and developers to help them create more quality code in a variety of programming languages such as python, javascript, typescript, ruby and go.
- GitHub bury its entire repository under the North Pole to prevent the apocalypse happeninggithub's data block will be continuously stored in many formats and buried in different locations on earth.