Skip to main content

Command Palette

Search for a command to run...

Accessing GitHub in the server using the deploy key

Published
2 min read

A deploy key is like a secret code that allows the computer to communicate with GitHub without using a username and password. Using the deploy key you can restrict the server to access only a single repository. The deploy key attaches to the public key in GitHub.

1. Connecting to the server

First, you have to connect to the server. Duh? you know? okay sure. Here is the command so you don’t have to search google.

ssh -i path-to-pem-file username@ipaddress

2. Generating SSH key

  1. You can generate the key by using the following command. If you need more details, you can check this out.

     ssh-keygen -t ed25519 -C "youremail@example.com"
    
  2. Now add your key to ssh-agent

     eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519
    

3. Adding SSH key as a deploy key

  1. Go to your repo URL

  2. Go to the settings of your repo.

    Untitled(2).png

  3. Go to the Deploy Keys and click on Add deploy key

    Untitled(1).png

    Untitled.png

  4. Copy the content of .pub key file from the server that you generated in step 1.

      cat ~/.ssh/id_ed25519.pub
    
     # copy the content
    
  5. Paste the key on the text box on Github. Also, add a title.

  6. Now check the connection to GitHub using

     ssh -T git@github.com
    
     Hi github-username/repo-name! You've successfully authenticated, but GitHub does not provide shell access.
    

    you may be asked "Are you sure you want to continue connecting (yes/no/[fingerprint])" Just hit yes

Ps. You can get more details here.

4. Cloning project from GitHub

git clone git@github.com:github-username/repo-name.git

Congratulation, you have cloned your and now have access to your single repo