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
- Run the installer (
bash <(curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh)
) - The docs show how to register to the atuin server (
atuin register -u <YOUR_USERNAME> -e <YOUR EMAIL>
) but not how to register to your own server. At least, not in the set up bit of the docs. But it is in the config section:sync_address
in~/.config/atuin/config.toml
. - Register a user (
atuin register -u <YOUR_USERNAME> -e <YOUR EMAIL>
) - I wanted to import all history (
atuin import auto
)
And that was it.
Second client
On the first client:
- Get your key (
atuin key
)
On the second client I did:
-
Create the config file directory (
mkdir -p ~/.config/atuin/
), and then symlink in the config file (which I have stored somewhere to keep it in sync across multiple machines) -
Run the installer (
bash <(curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh)
) -
login (
atuin login
) - you’ll need your username, key (from client 1), and password
Using it
I look forward to seeing how it works for me in practice!
You may also like:
- Making my ThinkPad LED flash 'decoded.legal' in morse code
- Keyboard shortcut for adding random albums to the playlist in ncmpcpp
- This is a test post
- Fixing Mastodon 'Error processing thumbnail for uploaded media' video uploading
- Upgrading the glitch-soc fork of Mastodon
- Very, very initial thoughts of the Xreal Air 2 Pro glasses and Debian 12
- Using Bitwarden as an AppImage on Debian with GNOME
- A web UI for label creation and printing on a Brother QL-710W on Linux
- Getting a Brother QL-710W label printer working via CUPS on Debian
- Desktop Linux: the software I'm currently using
- Fixing apt yarn key deprecation warning in Debian 12
- NetworkManager: automatically switch between Ethernet and Wi-Fi
- Backing up to a USB stick automatically via udev
- Automating actions in Nautilus (GNOME's file manager) with scripts
- Fixing SOGO error NSDataMalloc(instance) does not recognize stringByTrimmingSpaces