Pages: Welcome | Projects

Gnome Keyring avoidance

Tags: [ GNU/Linux ] [ security ]

I've been an i3wm user for a good amount of time. Then I upgraded my system to Fedora 25, and I decided to give Gnome Shell a try. I find myself to work quite decently, but sometimes I smash my face on the "everything in GUI" attitude of these days.

I'm a terminal person. When I try to log in servers using ssh keys, I really don't want the whole desktop environment to get shaded and a graphical log-in to ask me for the password. That whole screen flashing is a big cognitive noise!

By echoing the $SSH_AUTH_SOCK variable it gets fairly easy to understand what's going on… how to solve it, it's a bit more tricky. A user on IRC had the same problem and shared a shell script snippet, some time ago. I can't give him credit properly, since I don't remember the nick name.

I've refined it, and finally I've found a decent way of handling this problem:

function ssh_agent_bind()
    # No need unless gnome-keyring is in the way.
    [ ! "$SSH_AUTH_SOCK" =~ 'keyring' -a -e "$SSH_AUTH_SOCK" ] && return

    local agent_info_file="/var/run/user/$UID/ssh_agent_info"
    if ! [ -e "$agent_info_file" ]; then
        ssh-agent > "$agent_info_file"
    source "$agent_info_file"

    ps -P "$SSH_AGENT_PID" >/dev/null && {
        [ -e "$SSH_AUTH_SOCK" ] && return;

    ssh-agent > "$agent_info_file"
    source "$agent_info_file"