The joys of a self hosted Atuin server

Yesterday (or better last night) I set up my own Atuin shell history server. I've been using Atuin for a while now, since February'24 I think. But these were only the isolated shell histories of my 3 main machines. I wasn't aware of the Atuin history sync server, which I can easily self-host. Until now!

Atuin - Making your shell magical

Atuin - Documentation

Atuin - Server setup guide

Free History Hosting Service or Self-Hosted

The developers even host a public end-to-end encrypted Atuin History Sync Service for free. They couldn't see my history, but I don't want to rely on an external service provider (who maybe changes terms of service), when I can self-host this thing on my infrastructure which is already in place.

Features

Only with the server I can get the full potential from my collected CLI history. I have all the commands from all machines available on all of them instantly. It furthermore adds some more context to my inputs. I can filter commands by host, users, directories or sessions if I like, it also stores timestamps, duration and exit code, and then I can make a fuzzy search through them.

Atuin Setup

Atuin is packaged in the [extra] Arch repo which I enabled on my Artix systems. So it's pretty current. And it's the only package I need on the machines I want to use Atuin on. It also has a daemon in the binary, which needs to run in the background to get the full performance from the server.

On Artix I had to write a little OpenRC script to start/stop the Atuin daemon and put it into '/etc/init.d/atuin-daemon'. It has to be executable.

Then I had to add it to the OpenRC startup scripts and start it afterwards to avoid a reboot.

On systems with different init systems this process has to be done accordingly to the used init system. But most of the time you'll have to create your own init scripts (eg. for systemd).

After that comes the configuration of Atuin in the '~/.config/atuin/config.toml' user file. The defaults are pretty sensible and I just needed to add a few lines at the end of the file.

Later after the installation of the server I just had to adjust the 'sync_address' setting to point to my own server.

Now I had to add the Atuin history tool to the shell resource file. I show it here for the ZSH shell, but bash and others are similar:

After that I restarted my shell and imported my local history:

Now I could use Atuin already locally with my current history.

Server Installation

While the Atuin binary also includes the corresponding server, I chose the docker-compose setup though, because a postgresql database is also needed. Therefore I created an .env file containing the postgresql credentials, and a docker-compose.yml file.

.env:

docker-compose.yml:

I had to fix some file permission problems on my Proxmox container, which shouldn't be too difficult if needed. When everything was in place I already could start the server.

It should automatically restart now if I for example restart my server.

Create Account and first Login

Now I had to have the right server address in place in my Atuin config on my workstations: 'sync_address = "https://services.srv:8888"' and restarted my shell: 'exec zsh'. Then I entered the following command to create an account on my server:

Then I needed to log into my newly created account and did my first sync:

Now the workstation was already syncing but still lonely. If I wanted to merge all the history list into one on all computers I needed to get the right key for the repository while I'm logged into the first computer. This is the way to get the encryption key for the account to connect further systems:

This spitted out a list of words which I needed to provide for logging into subsequent machines:

With the last two commands I could add my other two machines to the merged history list. And it works perfectly! I have a merged history list from 3 machines which I can search through with fuzzy finding filtered by hosts, users, directories and sessions. I believe searching through time periods is also possible although I haven't checked that out yet.

TLS

Although TLS (https) is not strictly needed in a homelab environment I do appreciate the additional security. Especially because I have a local net certificate authority already in place. So I created a certificate signed by my local CA and added it to the server ~/config/ directory and edited the server.toml file accordingly.

If you really want this you need to create a certificate/key pair signed by your local Certificate Authority which must be added to your certificate store on all connected machines. But I won't cover that in this walkthrough. There are some good tutorials out there how to maintain your own CA. Maybe I'll make a tutorial on that later, too.

I'm already hooked

I've used Atuin in local mode for half a year now and got used to it's convenient features. But merged histories are a huge level higher. For example I used a lot of awk commands on my desktop for different purposes. Now I have these commands also available in the history of my other machines. Same with other commands like sed, grep or find. Or commands sequences with lots of pipes. All available everywhere. It's simply awesome! I can only recommend it to you!

All in all - Have fun!

-fab-

--

Back to index

Homepage

Proxied content from gemini://redterminal.org/gemlog/2024-08-19-The_joys_of_a_self_hosted_Atuin_server.gmi

Gemini request details:

Original URL
gemini://redterminal.org/gemlog/2024-08-19-The_joys_of_a_self_hosted_Atuin_server.gmi
Status code
Success
Meta
text/gemini;lang=en
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.