DEV Community

loading...
Cover image for How to clone your private repository from GitHub to server, Droplet, VDS, etc?

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

koddr profile image Vic Shóstak Originally published at Medium Updated on ・2 min read

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 happen when your run cat ./file.txt command at console?
  • Why a sudo command prefix are important?

Discussion (3)

Collapse
mrahmadawais 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 Author

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
mrahmadawais profile image
Ahmad Awais ⚡️

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

Forem Open with the Forem app