Systemd unit for kanata [Linux] #130
Replies: 7 comments 19 replies
-
Seems like |
Beta Was this translation helpful? Give feedback.
-
Unable to get this to work, can't find any devices. Maybe it runs with the wrong user? |
Beta Was this translation helpful? Give feedback.
-
checked error log
systemd runs as root, so i blindly added root to the input, uinput groups too early to get uinput?I wondered if the service was started at an early time when uinput could not be found, solutionI made the kernel load the uinput module into memory first, and suddenly it worked. add
|
Beta Was this translation helpful? Give feedback.
-
For whoever that gets |
Beta Was this translation helpful? Give feedback.
-
I didn't want to fight with permissions and all that stuff, so I made a system-wide config ( [Unit]
Description=Kanata keyboard remapper
Documentation=https://github.com/jtroo/kanata
[Service]
Type=simple
ExecStart=/home/user/.cargo/bin/kanata --cfg /home/user/.config/kanata/config-name.kbd
Restart=never
[Install]
WantedBy=default.target Also did this: # sudo systemctl daemon-reload # maybe this will be required when changing the service file
sudo systemctl start kanata
sudo systemctl enable kanata |
Beta Was this translation helpful? Give feedback.
-
For non systemd users:
/usr/local/bin/kanata-daemon.sh
|
Beta Was this translation helpful? Give feedback.
-
Thanks everyone for sharing. I was quite afraid to run such a program designed to process everything that is typed, so here is my step by step configuration on a Ubuntu 20.04 host, with a dedicated kanata user and a hardened systemd service configuration, to use without the Kanata TCP server: # allow a dedicated user group to use uinput kernel module
sudo groupadd uinput
sudo echo 'KERNEL=="uinput", MODE="0660", GROUP="uinput", OPTIONS+="static_node=uinput"' | sudo tee /etc/udev/rules.d/50-kanata.rules > /dev/null
# create the kanata user
sudo useradd --no-create-home --groups input,uinput --shell /bin/false --user-group kanata
# "install" kanata
sudo wget -O /usr/local/bin/kanata https://github.com/jtroo/kanata/releases/download/v1.7.0/kanata
sudo chown root:kanata /usr/local/bin/kanata
sudo chmod 754 /usr/local/bin/kanata
# create systemd unit
sudo echo "[Unit]
Description=Kanata keyboard remapper
Documentation=https://github.com/jtroo/kanata
[email protected]
[email protected]
[Service]
Type=simple
User=kanata
ExecStart=/usr/local/bin/kanata --quiet --cfg /my/kanata/config.kbd
Restart=no
# Security
CapabilityBoundingSet=
DeviceAllow=/dev/uinput rw
DeviceAllow=char-input
DeviceAllow=/dev/stdin
DevicePolicy=strict
PrivateDevices=true
BindPaths=/dev/uinput
BindReadOnlyPaths=/dev/stdin
BindReadOnlyPaths=/dev/input/
InaccessiblePaths=/dev/shm
LockPersonality=true
NoNewPrivileges=true
PrivateTmp=true
PrivateNetwork=true
PrivateUsers=true
# The following can not be enabled, otherwise Kanata can not open /dev/uinput.
# More hardening would require to explicitly list allowed system calls.
#ProtectClock=true
ProtectHome=true
ProtectHostname=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectSystem=strict
ProtectControlGroups=true
# Allow only on AddressFamily and then deny it to effectively deny everything
RestrictAddressFamilies=AF_AX25
RestrictAddressFamilies=~AF_AX25
RestrictNamespaces=true
SystemCallArchitectures=native
SystemCallErrorNumber=EPERM
SystemCallFilter=@system-service
SystemCallFilter=~@privileged
SystemCallFilter=~@resources
RemoveIPC=true
IPAddressDeny=any
RestrictSUIDSGID=true
RestrictRealtime=true
MemoryDenyWriteExecute=true
UMask=0077" | sudo tee /etc/systemd/system/kanata.service > /dev/null
sudo systemctl daemon-reload Enable the systemd unit if you want it to start automatically: Finally reboot the system. |
Beta Was this translation helpful? Give feedback.
-
~/.config/systemd/user/kanata.service
systemctl --user start kanata.service
to start kanata daemonsystemctl --user enable kanata.service
so it may autostart whenever the current user logs in.systemctl --user status kanata.service
to check if kanata daemon is running or not.Beta Was this translation helpful? Give feedback.
All reactions