Monday, November 21, 2022

Mastodon gateway on Linux

Install toot

As root (or add sudo to commands) install Python 3.X if you have not already with

yum install python3

then run

pip3 install toot

toot login

Answer instance with your instance hostname, then get code from browser. Note I had an issue (see pic) when I tried this again for a second server which appears to be and server customization issue. Fortunately I was able to copy the config file from the first server to the second. This would indicate the info is not client host of user linked.

Once the config file is set up for the user you can test with something simple like

toot post "toot test"

Note the double quotes. See the usage docs for more complicated posts.

Toot when server starts

We need to create some files with:

vi /root/


toot post "$HOSTNAME is back up" 

chmod 744 /root/

The 2>&1 | tee -a /var/log/toots.log bit is only if you want to log the toots.

vi /etc/systemd/system/toot.service


Description=Toots that the system is back up






Now enable it, try it and check it with:

systemctl enable toot.service

systemctl start toot.service

status -l toot.service

If everything is working then you should see something like this:

# systemctl status -l toot.service

● toot.service - Toots that the system is back up

   Loaded: loaded (/etc/systemd/system/toot.service; enabled; vendor preset: disabled)

   Active: inactive (dead) since Mon 2022-11-21 14:24:52 EST; 19s ago

  Process: 2622 ExecStart=/root/ (code=exited, status=0/SUCCESS)

 Main PID: 2622 (code=exited, status=0/SUCCESS)

Nov 21 14:24:51 systemd[1]: Started Toots that the system is back up.

Nov 21 14:24:52[2622]: Toot posted:

ssh gateway

To be safer you should really create a toot user. As root run

adduser toot

passwd toot

mkdir -p ~toot/.config/toot

chown -R toot.toot ~toot/.config

chmod -R 700 ~toot/.config

cp /root/.config/toot/config.json ~toot/.config/toot

chown -R toot.toot ~toot/.config/toot/config.json

chmod 600 ~toot/.config/toot/config.json

su - toot

Note you are now acting as user toot. 

Create a simple post script. This example is as basic as it gets you can be way more fancy.



toot post "$*" 2>&1 | tee -a /var/log/toots.log

chmod 755

You might want a quick test like

~toot/ ssh gateway test

Note no double quotes. The script deals with that which we will need for the next bit.

Using the ssh gateway.

For the examples below I'm using the gateway IP address of Replace it with yours.

Login to the PC you want to "toot" from.

Open a command / terminal window and change to the folder you want the toot files in.

Generate a key with

ssh-keygen -q -f toot_rsa

Take defaults / just press ENTER at each prompt.

Note this is creating a private key file we can use separately from default so it does not need a password on it.

Now we want to give the server the public copy so in future they will know it is us. It creates the .ssh folder if need be.

cat | ssh toot@ -o StrictHostKeyChecking=no "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1

It will ask you for the password to connect but you will not need to again. You can test this with

ssh -o StrictHostKeyChecking=no -i ./toot_rsa toot@

or if you just want to go for it

ssh -o StrictHostKeyChecking=no -i ./toot_rsa toot@ ./ ssh gateway test from client

toot and RSS feed

Lastly we can use this setup to toot an RSS feed.

Install feedexec back on the gateway server as user toot. 

pip3 install feed2exec

Note you may need to install some dependencies as well. I needed to install these too.

pip3 install sqlite3 sqlite pysqlite

Test with 

feed2exec parse --output echo --args '{item.title}'

If that works, create the file ~/.config/feed2exec.ini

vi ~/.config/feed2exec.ini


url =

output = feed2exec.plugins.exec

args = /home/ {item.title}. For details see {}

Just change the RSS URL and message as needed. To then post any new items call
feed2exec fetch
or better yet set up cron with
crontab -e
adding the line
00 * * * * /home/toot/.local/bin/feed2exec fetch
to run it every hour.

No comments:

Post a Comment