Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Created April 5, 2017 21:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xenithorb/4465d755546e58fdbf73c872448acd42 to your computer and use it in GitHub Desktop.
Save xenithorb/4465d755546e58fdbf73c872448acd42 to your computer and use it in GitHub Desktop.
systemd user unit: Custom SSH_AUTH_SOCK variable for X11/Wayland (Fedora/GNOME)
# Because setting environment variables is HARD!! (apparently)
# 1. Disable gnome-keyring-ssh, or just allow ExecStartPre to do it:
# $ NAME="gnome-keyring-ssh.desktop"; cat "/etc/xdg/autostart/${NAME}" \
# <(echo "Hidden=true") > "${HOME}/.config/autostart/${NAME}"
# 2. $ mkdir -p ~/.config/systemd/user
# 3. Place this file in ~/.config/systemd/user/ssh-auth-sock.service
# 4. $ systemctl --user enable --now ssh-auth-sock.service
# 5. Logout or reboot.
[Unit]
Description=Custom SSH_AUTH_SOCK variable for X11/Wayland
[Service]
Type=oneshot
Environment=SSH_AUTH_SOCK=%h/.ssh/ssh-agent.socket
Environment=NAME=gnome-keyring-ssh.desktop
ExecStartPre=/bin/bash -c 'cat /etc/xdg/autostart/${NAME} \
<(echo "Hidden=true") > %h/.config/autostart/${NAME}'
ExecStart=/usr/bin/systemctl --user set-environment \
SSH_AUTH_SOCK=${SSH_AUTH_SOCK} \
GSM_SKIP_SSH_AGENT_WORKAROUND="true"
# See the below link for why we need GSM_SKIP_SSH_AGENT_WORKAROUND:
# https://git.gnome.org/browse/gnome-session/tree/gnome-session/main.c?h=3.24.0#n419
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment