How to Use GitHub Deploy Keys

Alternative Text
by Dmitry Elisov
Oqtacore CTO
1779

Table of content

alt

How to Use GitHub Deploy Keys on Linux and Windows

Learn how to set up GitHub deploy keys on both Linux and Windows systems in this detailed, step-by-step guide.

We will first walk you through the setup process on Linux, followed by a guide to setting up deploy keys on Windows.

GitHub deploy keys offer a secure and convenient method of granting access to your GitHub repositories. Different projects utilize deploy keys to maintain a high level of security, ensuring that access is restricted to specified individuals or systems. Instead of using personal GitHub accounts, which can potentially be compromised leading to unauthorized access to all repositories a person has access to, deploy keys restrict access to a single repository, providing a more secure environment. Moreover, deploy keys simplify the automation of pulling code into production or CI/CD pipelines without having to manage individual permissions.

Deploy keys come with various settings on GitHub that help in enhancing security. They can be set to “read-only,” which allows pulling of the repository contents but not pushing any changes, thus safeguarding the repository from any unwanted alterations. Also, by enabling deploy keys at an organizational level, you streamline access across multiple repositories, which can be a boon for larger projects.

Let’s delve deeper to understand how you can set up GitHub deploy keys on Linux and Windows systems.

How to Use GitHub Deploy Keys on Linux and Windows

Learn how to set up GitHub deploy keys on both Linux and Windows systems in this detailed, step-by-step guide. We will first walk you through the setup process on Linux, followed by a guide to setting up deploy keys on Windows.

Setting Up GitHub Deploy Keys on Linux

Follow these step-by-step instructions to set up GitHub deploy keys on a Linux system:

Step 1: Install the Necessary Tools

Before we begin, ensure that Git and SSH are installed on your Linux system. Open a terminal and run the following commands to install them:

 

sudo apt-get update
sudo apt-get install git
sudo apt-get install openssh-server

Step 2: Generate SSH Keys

Use the `ssh-keygen` command to generate a new SSH key pair. You will use this key pair as your deploy key.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Follow the on-screen prompts, opting to save the key with a distinct name to differentiate it from other SSH keys.

Step 3: Add the SSH Key to the SSH Agent

Add your new key to the SSH agent with the following command:

ssh-add ~/.ssh/your-ssh-key-filename

Step 4: Add the SSH Key to Your GitHub Repository

Navigate to your GitHub repository and go to “Settings” > “Deploy keys” > “Add deploy key”. Here, add a title for your key and paste the public key, which you can get using the following command:

cat ~/.ssh/your-ssh-key-filename.pub

Click “Add key” to save the deploy key.

Step 5: Clone Your Repository

Now clone your repository using the SSH URL:

git clone git@github.com:your-username/your-repository.git

You should now have configured GitHub deploy keys on your Linux system successfully.

## Setting Up GitHub Deploy Keys on Windows

Here’s how you can set up GitHub deploy keys on a Windows system:

Step 1: Install Git for Windows

Download and install [Git for Windows](https://gitforwindows.org/) by following the on-screen instructions.

Step 2: Generate SSH Keys

Open Git Bash and generate a new SSH key pair using the following command:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Step 3: Add the SSH Key to the SSH Agent

Start the SSH agent in the background and add your SSH key:

eval $(ssh-agent -s)
ssh-add ~/.ssh/your-ssh-key-filename

Step 4: Add the SSH Key to Your GitHub Repository

On your GitHub repository, navigate to “Settings” > “Deploy keys” > “Add deploy key”. Provide a title and paste the contents of your public SSH key, which can be displayed using the command:

cat ~/.ssh/your-ssh-key-filename.pub

Step 5: Clone Your Repository

Clone your repository using the SSH URL:

git clone git@github.com:your-username/your-repository.git

Congratulations, you have successfully set up GitHub deploy keys on your Windows system. Ensure to always keep your private keys secure and to add your public key only to the necessary GitHub repositories to maintain a secure environment.

At the end of the guide, we trust that you are well-versed with GitHub deploy keys and their setup on Linux and Windows. Always remember, the prudent use of deploy keys not only secures your project but also facilitates a seamless development workflow by leveraging the different settings available for deploy keys on GitHub. Make the most of deploy keys to enhance your project’s security and workflow efficiency.

Rate this article
Please wait...