Keeping bash history in sync using atuin and a self-hosted sync server

I read an interesting blogpost today, entitled “I quit my job to work full time on my open source project”.

I’m full of respect for someone who does this - I know what it’s like to quit employment and set up on your own, as I did this eight years ago now, walking away from job as an employed lawyer to start our own law firm - and, well, the project itself looks amazingly useful too: keeping bash (and other shell) history in sync, across multiple machines.

That project is atuin.

I’ve actually got a feeling that I heard of it last year, perhaps, but I didn’t do anything with it at the time.

Today, I decided to give it a go.

The atuin client can help with bash history search on its own, but since I often move between machines, having multiple machines in sync sounds very useful.

So I wanted the sync functionality but, even though it is encrypted, I’d prefer to run my own sync server, so I did that first.

Setting up the server

atuin

The server is the same as client, and the official installation method is a piped remote bash script:

bash <(curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh)

I reviewed it, and it boiled down to:

LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/atuinsh/atuin/releases/latest)

LATEST_VERSION=$(echo "$LATEST_RELEASE" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')

echo "https://github.com/atuinsh/atuin/releases/download/$LATEST_VERSION/atuin_${LATEST_VERSION//v/}_amd64.deb"

curl -Lo /tmp/atuin.deb "https://github.com/atuinsh/atuin/releases/download/$LATEST_VERSION/atuin_${LATEST_VERSION//v/}_amd64.deb"

sudo apt install /tmp/atuin.deb

And then adding an entry to ~/.bashrc.

This seemed sensible, and safe, enough, so I ran the installer.

postgresql

It uses postgresql as the database:

sudo apt install postgresql postgresql-contrib -y

sudo systemctl enable --now postgresql

sudo -u postgres createuser atuin

sudo -u postgres createdb -O atuin atuindb

sudo -u postgres psql

alter user atuin with encrypted password 'use-a-better-password-than-this';

quit;

atuin server config

atuin needs a server config file (which is different to the client config file):

mkdir -p ~/.config/atuin/

tee ~/.config/atuin/server.toml <<EOF
host = "0.0.0.0"
port = 8888
open_registration = true
db_uri="postgres://atuin:use-a-better-password-than-this@127.0.0.1/atuindb"
EOF

Note that this will do http (not https) over port 8888. Since the server is non-public, and the history is encrypted, I felt that not using https was a suitable tradeoff for now. I might change that in future.

Obviously, there were firewall configurations to change too, to allow in (select) traffic to 8888.

systemd

You can test the server with atuin server start. It worked.

I want the server to run on boot, as my user, so I created a systemd profile(?) for it:

sudo tee /lib/systemd/system/atuin.service <<EOF
[Unit]
Description=Run atuin as user neil
DefaultDependencies=no
After=network.target

[Service]
Type=simple
User=neil
Group=neil
ExecStart=/usr/bin/atuin server start
TimeoutStartSec=0
RemainAfterExit=yes
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF


sudo systemctl daemon-reload

sudo systemctl enable --now atuin.service

sudo systemctl status atuin.service

And it worked. Excellent.

Client

Setting up the clients is easier.

First client

And that was it.

Second client

On the first client:

On the second client I did:

Using it

I look forward to seeing how it works for me in practice!