Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister
Created March 19, 2019 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaswerkmeister/bf2a52453cc12ea2f86e597c6e77423f to your computer and use it in GitHub Desktop.
Save lucaswerkmeister/bf2a52453cc12ea2f86e597c6e77423f to your computer and use it in GitHub Desktop.
systemd user units to wipe sensitive SSH keys from the SSH agent every night
[Unit]
Description=Wipe sensitive SSH keys from the SSH agent
[Service]
Type=oneshot
ExecStart=/usr/bin/ssh-add -d ${HOME}/.ssh/KEY-NAME-1 ${HOME}/.ssh/KEY-NAME-2 …
# don’t fail if the key wasn’t in the SSH agent in the first place
SuccessExitStatus=1
[Unit]
Description=Wipe sensitive SSH keys from the SSH agent every night
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
@lucaswerkmeister
Copy link
Author

Also, consider adding aliases like the following to your .bashrc:

alias npm='systemctl --user start wipe-ssh-agent && npm'
alias grunt='systemctl --user start wipe-ssh-agent && grunt'
alias composer='systemctl --user start wipe-ssh-agent && composer'
# ...

Or use a more sophisticated solution to protect your system from rogue npm packages and similar issues, such as fresh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment