How To Setup Deploy ๐Ÿ”‘ In Github Repository?

How To Setup Deploy ๐Ÿ”‘ In Github Repository?


3 min read

What is the Deploy key?

Deploy key is an SSH key configured in your repository to grant read or write access without logging into your GitHub account.

Why should I use it?

Using Deploy Keys can come in handy when you don't want to login to your GitHub account on a machine or just wanted to configure a single repository in that machine.

As the name says, its primary function is to be used in places where read-only access is needed. Therefore keep the repository safe from the attack, in case the server-side is fallen.

Before we start first, let's create a new Github Repository if you don't have 1 already.

โš™๏ธ Generating SSH Keys

  1. Open Terminal / Open Git Bash if you are on windows
  2. Run ssh-keygen -t ed25519 -C "[email protected]" make sure to replace [email protected] with your email which is associated

When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. You also save it in any location

Enter a file in which to save the key (/xyz/xyz/.ssh/id_ed25519):

At the prompt, type a secure passphrase

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

๐Ÿ”ฉ Configuring Local Machine

Add your SSH private key to the ssh-agent. If you created your key with a different name, in a different location, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

Before adding a new SSH key to the ssh-agent make sure the ssh-agent is running.

eval "$(ssh-agent -s)"

The above cmd will output similar to Agent pid 111931 which means the agent is up & running

ssh-add {your-key-location}

Replace {your-key-location} with the actual path for that key file

๐Ÿ”ฉ Configuring Github Repository

Copy public key from the {key-file-name}.pub file

  1. Navigate to your repository
  2. Click โš™๏ธ Settings
  3. Click Deploy keys
  4. Click Add deploy key

๐Ÿงช Testing

To Test if your key is configured correctly run the below cmds

Read Only Test

git clone [email protected]:{username}/{repository}.git

Above cmd should output something similar to below output

Write Test

Navigate Into The Folder

cd your-repository-path

Configure Git identity

git config "[email protected]"
git config "Your Name"

Create A New File


Add Some Content To The File

echo "## Hello World" >>

Add & Commit The File

git add
git commit -m "๐ŸŽ‰ Successfully Pushed Using Deploy Keys"

Push To Github

git push

๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰ Congrats you have successfully configured the repository with SSH Deploy key ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

Questions or feedback? Please comment below.

See all my projects at Github.

Follow me on Twitter for updates