How to setup a terminal pastebin instance using fiche

2020-10-16

(last time edited: 2020-11-02)

tags: linux, services

fiche is a command line pastebin for sharing terminal output.

I have used Termbin for a while and it's a great service. It can be really useful for sharing stuff on the Internet; scripts, pieces of codes, terminal output errors and any kind of interesting text.

The usage is pretty easy.

$ echo hello world | nc termbin.com 9999

$ cat file.txt | nc termbin.com 9999

In the commands above we are piping text from cat/echo to the GNU netcat utility and then netcat sends data to the fiche service using port 9999.

I decided to create a fiche instance on my server just for fun and it's very simple.

Create a new user in your system.

# adduser fiche

Remove fiche password.

# passwd -l fiche

Log in as fiche user.

# su - fiche

Then create a bin-fiche-data-storage-whatever directory and point the NGINX web server root directory location for fiche's data. You can also create a directory in /tmp if you want. I prefer to do it in a home dir.

$ mkdir ~/bin

You wanna make sure your web server is configured properly and serving data from a "bin" subdomain, because it looks cool and simple.

The NGINX configuration to serve uploaded data should look like this.

server {
    listen 443 ssl;
    server_name bin.yourdomain.com;
    charset utf-8;
    location / {
        root /home/fiche/bin;
        index index.txt index.html;
    }
}

These custom configurations are usually stored in a conf.d dir: /etc/nginx/conf.d/nginx-fiche.conf

NGINX should be able to read the configuration once you restart it.

# nginx -s reload

Notice: If NGINX is not reading the custom configuration make sure the http block inside /etc/nginx/nginx.conf included the conf.d dir.

http {
    ...
    include conf.d/*.conf;
    ...
}

Ok, let's run fiche now. You can execute it as root with the -u argument declaring the program to run as a 'fiche' user without privileges.

# fiche -u fiche -o /home/fiche/bin/ -d bin.yourdomain.com -l /tmp/fiche.log

Make your first test from your workstation.

$ echo hello world | nc bin.yourdomain.com 9999

If everything went correctly you should receive an url pointing to your server's subdomain serving the text in a 4 characters uri.

fiche in Void Linux

In Void Linux there is already a runit service written by default when you install fiche. All you got to do is edit it a bit and symlink it. And create the NGINX config to serve the files.

Notice: You don't need to create the fiche user. Runit takes cares of this. Also all data gets saved in /var/tmp/fiche instead of /home/fiche/bin

First edit it.

# vi /etc/sv/fiche/run

It should look something like this.

Edit the domain to something like bin.yourdomain.com or p.yourdomain.com. Remember it should be the same domain your put in the NGINX fiche config. You can add more arguments if you want. Such as -S -s 6, etc. The use of -S is encouraged.

#!/bin/sh
exec chpst -u _fiche:_fiche fiche -d bin.yourdomain.com -S -o /var/tmp/fiche -l /var/log/fiche/log

Now symlink fiche to runit.

# ln -s /etc/sv/fiche /var/service

Fiche will start automatically and will be managed by runit. You can look at your other services by running this command.

# sv /var/service/*

Happy hacking!