How to Create Your Own GitHub Gist using Opengist

Spread the love

Opengist is a lightweight, self-hosted Github Gist server for Linux. Unlike other solutions, it takes advantage of Git-specific features to quickly upload, browse, and revise your text files. Here, we show you how to install and host your own Opengist server on Ubuntu Linux.

Content

Why Host Your Own Gist Server with Opengist

One of the biggest selling points of Opengist is that it’s a Pastebin-like service that uses Git for its backend. This makes Opengist easy to pick up and host on Linux for anyone already familiar with Git-like services with Gist support such as Github and Gitlab.

Another strength of Opengist is that it can track user-specific pastes and provide controls to manage paste visibility. As a result, Opengist can be a self-hosted hub for sharing text between your small peer group.

Lastly, Opengist doesn’t require overhead to run. Its default config only relies on a single Docker container and data store, which you can either set as an internal volume or as a bind mount to your filesystem. This means you can run Opengist even on low-end systems without a lot of spare resources.

Good to know: learn the basics of source code management by going through our comprehensive beginner’s guide to Git.

Preparing the System for Opengist

Assumption: This tutorial is done on an Ubuntu 24.04 VPS with at least 2 GB of RAM and 25 GB of disk space. It also assumes that you currently own a domain name and that you can add an “A” DNS record to it.

Note: This section focuses on installing Docker on Ubuntu-based systems. To install it on a different distro, check out our general guide to installing Docker on Linux.

The first step in deploying Opengist to your machine is to obtain and install Docker, Nginx, and Certbot. To do that, first fetch the signing key for the Docker project:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Create a new repository file under “/etc/apt/sources.list.d/”:

sudo nano /etc/apt/sources.list.d/docker.list

Paste the following line of code inside your new repository file:

deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu noble stable

Save your repository file, then update and upgrade all the existing packages in your system:

sudo apt update && sudo apt upgrade

Fetch the Docker binary along with its Compose plugin and dependencies:

sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-buildx-plugin nginx

Make sure that the “core” snap package is present in your system:

sudo snap install core

Install the Certbot snap package from the Electronic Frontier Foundation (EFF):

sudo snap install certbot --classic

Installing and Running Opengist

Create a new folder for Opengist in the current user’s home directory, then go inside it:

mkdir -p ~/opengist/data && cd ~/opengist

Use your favorite text editor to create a new “docker-compose.yml” inside your Opengist folder:

nano ./docker-compose.yml

Paste the following block of code inside your new compose file:

services:
  opengist:
    image: ghcr.io/thomiceli/opengist:1.7
    container_name: opengist
    restart: unless-stopped
    ports:
      - "6157:6157"
      - "2222:2222"
    volumes:
      - ./data:/opengist"

Save your “docker-compose.yml” file, then run the following command to build and install Opengist to your system:

docker compose up -d

Confirm that Opengist is up and running by listing all the active Docker containers in your machine:

docker ps

On a side note: learn how to move your Docker containers to a new host.

Creating an SSL Reverse Proxy for Opengist

At this point, you now have a partially working Opengist instance running at port 6157. In order to use it securely over the internet, you need to pass it through an SSL reverse proxy using Nginx.

To do that, create a new “A” DNS record on your domain name pointing to the IPv4 address of your Opengist machine.

Go back your server’s terminal, then create a new site configuration file for Opengist:

sudo nano /etc/nginx/sites-available/opengist

Paste the following block of code inside your new config file:

server {
 
        server_name SUBDOMAIN.YOUR-ROOT.DOMAIN;
 
        location / {
                proxy_pass http://127.0.0.1:6157;
                proxy_http_version 1.1;
                proxy_redirect off;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
        }
}

Save your site config file, then create a symbolic link from “/etc/nginx/sites-available/” to “/etc/nginx/sites-enabled/”:

sudo ln -s /etc/nginx/sites-available/opengist /etc/nginx/sites-enabled/

Confirm that your Nginx config is working properly, then start the web server using systemctl:

nginx -t
sudo systemctl enable --now nginx.service

Register your Opengist system using your email address to the EFF:

sudo certbot register --agree-tos -m YOUR@EMAIL.ADDRESS

Generate a new SSL certificate for your domain name using Certbot:

sudo certbot --nginx -d SUBDOMAIN.YOUR-ROOT.DOMAIN

Confirm that your website is accessible over the internet by opening a web browser and navigating to your domain name.

Tip: learn how encryption works on the internet by generating your own SSL certificates with OpenSSL.

Creating Your First Gist with Opengist

By default, Opengist doesn’t provide an administrator account for your personal instance. To create one, you need to register it first through your instance’s web interface.

Start by navigating to your Opengist’s subdomain, then click the Register button on the page’s upper right corner.

Provide a username and password for your admin account, then click Register to create it.

Doing this will automatically log you in to the Opengist interface and give you a prompt for your first gist page. Either type or paste a snippet of text inside the input box, then click Create Public Gist to generate your first gist.

Note: you can set the privacy settings of your gist by clicking the Downward Arrow beside the Create Public Gist button.

You can now share your new gist file to anyone by copying its link from your browser’s address bar and sending it to your recipient.

Creating and Updating a Gist using SSH

Aside from the web interface, Opengist also supports gist submission and edits directly from the Git CLI client. This is helpful if you’re working on a terminal-only session and you don’t have access to a graphical interface.

Create a new folder for your gist page in your user’s home directory:

mkdir ~/my-gist && cd ~/my-gist

Either copy in or create a new text file containing your gist data, then initialize a new Git repository inside your new folder:

cp ~/my-text-file.txt ~/my-gist/
git init

Add your folder’s files to your new Git repo, then create its first commit:

git add .
git commit -m "My first Opengist commit."

Set the remote endpoint for your local Git repo to your Opengist server:

git remote add origin https://SUBDOMAIN.YOUR-ROOT.DOMAIN/init

Send your new repository to your Opengist server:

git push -u origin master

Provide your Opengist credentials, then press Enter to confirm the push command.

Copy the Git command that Opengist returns on your terminal session, then run it to set the new remote origin for your repository.

Confirm that you’ve saved your gist properly by looking at your server’s web interface.

Hosting your own Opengist server on Linux and creating Github-like gist pages are just some of the things that you can do with self-hostable software. Explore more about self-hosting by looking at some of the best self-hosted alternatives to Github today.

Image credit: Joan Gamell via Unsplash. All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Ramces Red
Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Leave a comment