Is there a way to remove all the ssh keys added to ssh-agent when the user locks the system?

Starx

I have a bunch of keys added to the ssh-agent, keys to servers, repositories, etc.

Is there a way to remove all the ssh keys added to ssh-agent when the user locks the system?

My system right now is Ubuntu Desktop 16.04 with GNOME 3

Jakuje

You can watch for the events in DBUS and on lock call ssh-add -D to remove all keys from the agent:

#!/bin/bash
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
  while read x; do
    case "$x" in 
      *"boolean true"*) echo SCREEN_LOCKED; ssh-add -D;;
      *"boolean false"*) echo SCREEN_UNLOCKED;;  
    esac
  done

But you need to export the SSH_AUTH_SOCK environment variable to this script, so it would be able to access your agent.

You can store the above into the script clean_lock.sh, set execute bits (chmod u+x clean_lock.sh) and run the script in background ./clean_lock.sh &.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to list keys added to ssh-agent with ssh-add?

Is it possible to keep added ssh keys in ssh-agent after reboot? (using keychain)

System locks up, but accessible by SSH

Start Pageant SSH-Agent and load all keys in a folder

gpg-agent and SSH: No keys

GIT push Unauthorized when SSH keys already added

ssh keys ssh-agent bash and ssh-add

Start a system wide SSH agent

SSH - is this the correct way to forward agent?

Rename SSH Key Agent that was already added

SSH Agent admitted failure to sign using the keys

ssh not using agent-forwarded keys

openssh: Have ssh add keys to agent as needed

ssh agent forwarding failing at 6 keys

Can't remove keys from ssh-agent. Even rebooting doesn't help

manage many ssh keys via ssh-agent

Encrypted USB with SSH keys system

SSH agent forwarding mixed with su user -

Use a specific SSH key-pair when connecting via ssh, and temporarily ignore all other keys?

Does the default per user .ssh/config file override all options in system wide ssh_config?

`ssh-agent` asks passphrase after it has been added

gpg-agent refuses SSH keys with ssh-add reporting "agent refused operation"

SSH Agent Forwarding not working even when using `ssh -A`

Start ssh-agent when windows boots along with ssh passphrase

ssh-agent does not work when executing ssh command

no prompt when connected to SSH using agent forwarding

Is there any way to automatically accept SSH host keys—even when keys are changed—in PuTTY?

ssh keys and working of ssh

SSH Agent forwarding using different usernames and different keys