How to start {gpg,ssh}-agent with systemd
To get rid of the convoluted and error prone start_agent function in .bashrc, just start ssh-agent and gpg-agent as user service with systemd. A big, fat warning before: Don’t even try to use gpg-agent as a replacement for ssh-agent! It’s so buggy that it won’t work!
To start the agents as user service, you have to create the following services in $HOME/.config/systemd/user (create the directory if it doesn’t exist):
gpg-agent.service:
[Unit] Description=GnuPG private key agent IgnoreOnIsolate=true [Service] Type=forking ExecStart=/usr/bin/gpg-agent --daemon Restart=on-abort [Install] WantedBy=default.target
ssh-agent.service:
[Unit] Description=SSH key agent [Service] Type=forking Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket ExecStart=/usr/bin/ssh-agent -a $SSH_AUTH_SOCK [Install] WantedBy=default.target
Then enable them:
$ systemctl --user enable gpg-agent.service $ systemctl --user enable ssh-agent.service
Now add
export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket"
to your .bashrc, .profile or whatever and re-login. If the agents linger (i. e. aren’t restarted), add the following entry in /etc/systemd/logind.conf:
KillUserProcesses=yes
and restart systemd-logind. This kills all processes started on login, including kdeinit4 and stuff. Warning: This may kill your current X-Session!
Now you have to ssh-add your key every time you log out, but you don’t have to kill all the KDE-cruft any more. There always is a tradeoff 🙂
SDDM and keyboard layouts
Creating a config snippet with localectl doesn’t work, but lo and behold, there’s a workaround. Just add
setxkbmap de,us nodeadkeys
to /usr/share/sddm/scripts/Xsetup
To change the X-Server layout, create a xorg.conf that does it right.
Restore KDE-Session
Well, that’s a problem. Most KDE-Apps remember their position, even their screen, but chromium does not. The closest thing to get it right:
- Go to System Settings -> Startup and Shutdown -> Desktop Session and set it to “Restore manually saved session”
- Place your programs and windows
- Save session
- Go to Startup and Shutdown -> Autostart and add chromium as command. Then edit Properties… -> Application and change the command to:
chromium --disable-session-crashed-bubble --restore-last-session
This restores the last session without telling you that chromium crashed. Unfortunately, all windows appear on the current desktop, so you have to move them manually. AFAICT they keep their position, so defining keyboard shortcuts to move windows to another desktop, e. g. Meta-2 for desktop 2, makes this easy.