DEV Community

Cover image for How to clone your private repository from GitHub to server, Droplet, VDS, etc?
Vic Shóstak
Vic Shóstak

Posted on • Edited on • Originally published at Medium

How to clone your private repository from GitHub to server, Droplet, VDS, etc?

Introduction

Welcome back! The “(Quick) How to” series continue.

Today, we solve huge misunderstood thing: clone private repository from GitHub on your server. Don’t switch the channel 😃

Objectives of the article

  1. Show one of the easiest ways to clone private GitHub repository.
  2. Train your console skills.

Prepare setup

First, connect to your server (Droplet, VDS, etc) and generate SSH key:



$ sudo ssh-keygen


Enter fullscreen mode Exit fullscreen mode

If you want, choose path and name for your key. I always use default path (~/.ssh) and name, like project_name_rsa.

Next step, create SSH config:



$ sudo cat >~/.ssh/config <<EOL

Host project_name
Hostname github.com
User git
IdentityFile ~/.ssh/project_name_rsa

EOL


Enter fullscreen mode Exit fullscreen mode

Don't forget to change my project_name to yours!

OK! Copy public key to clipboard and go to your GitHub repository settings:



$ sudo cat ~/.ssh/project_name_rsa_key.pub


Enter fullscreen mode Exit fullscreen mode

Add copied public key to Deploy Keys section:

github allow write access

Don’t forget to check Allow write access.

That’s it. 🎉

let's clone private git repo

Let’s clone it!

You may git clone your private repository to server by command:



$ sudo git clone project_name:<user>/<repo>.git


Enter fullscreen mode Exit fullscreen mode

How to update?

For update, type into your project directory:



$ git pull


Enter fullscreen mode Exit fullscreen mode

What’s next?

Get automation of routine tasks on a new server (Droplet, VDS, etc) with Virtual Server Auto Config (or VSAC for short). Just git clone and run it! 👇

GitHub logo koddr / vsac

✅ Аutomation of routine tasks on a new server for humans. Only verified configs and best practices. Just git clone and run it!

✅ Virtual Server Auto Config

version linux license

The Why?

Аutomation of routine tasks on a new server for humans. Only verified configs and best practices.

Just git clone and run it!

For GNU/Linux Debian 9 Stretch

Clone this repo:

foo@bar:~$ git clone https://github.com/koddr/vsac.git
Enter fullscreen mode Exit fullscreen mode

Run ./init.sh from root dir:

foo@bar:~$ cd vsac
foo@bar:~$ sudo chmod +x ./init.sh
foo@bar:~$ sudo ./init.sh [OPTIONS]
Enter fullscreen mode Exit fullscreen mode

Options

  • --webserver [NAME] — web server name, you want to install (support: nginx);
  • --python [VERSION] — Python 3 version, you want to install (support: 3.5.x, 3.6.x, 3.7.x, 3.8.x)
  • --postgresql [DATABASE] — PostgreSQL with database name, you want to install

Nginx configuration

user nginx
+ worker_processes auto;

events {
+   use epoll;
    worker_connections 1024;
+   multi_accept on;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log off;
    error_log /var/log/nginx/error.log crit;
+   server_tokens off;

+   keepalive_timeout 30;
+   keepalive_requests 100;

+   reset_timedout_connection on;
+   client_body_timeout
Enter fullscreen mode Exit fullscreen mode

Photos by

[Title] Nicole Wolf https://unsplash.com/photos/CZ9AjMGKIFI
[1] Azharul Islam https://unsplash.com/photos/9LMGWHqUwnc

P.S.

Questions for self-study practice:

  • Which console command may generate SSH key?
  • What’s to happen when you run cat ./file.txt command at console?
  • Why a sudo command prefix is important?

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

❗️ You can support me on Boosty, both on a permanent and on a one-time basis. All proceeds from this way will go to support my OSS projects and will energize me to create new products and articles for the community.

support me on Boosty

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My main projects that need your help (and stars) 👇

  • 🔥 gowebly: A next-generation CLI tool that makes it easy to create amazing web applications with Go on the backend, using htmx, hyperscript or Alpine.js and the most popular CSS frameworks on the frontend.
  • create-go-app: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.

Other my small projects: yatr, gosl, json2csv, csv2api.

Top comments (4)

Collapse
 
ahmadawais profile image
Ahmad Awais ⚡️

Awesome! One minor issue is that the host should also be github.com

In your ~/ssh/config the first line

Host github.com

Collapse
 
koddr profile image
Vic Shóstak

Actually, nope :) but thx to reply.

Host variable is a simple alias for calling this block in ssh <host> or git clone <host>:... and else. You can set any valid word for it, like usual alias for console commands in bash config.

Collapse
 
ahmadawais profile image
Ahmad Awais ⚡️

I know right. But it only worked once I did that. Maybe server was configured that way or something?

Collapse
 
skepticmodder profile image
Arun

@koddr will 'Deploy keys' work on private repo in a free GitHub account ?
When I try I get the error:
Cloning into 'test'...
Warning: Permanently added the ECDSA host key for IP address '192.30.255.113' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.