laggardkernel / zsh-gpg-agent

Use gpg-agent as an agent for SSH

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gpg-agent

License: MIT

ZSH plugin. Goodies for gpg-agent like autostart, SSH_AUTH_SOCK export and remote socket cleanup, etc.

The plugin is designed as a Prezto module, but it's also compatible with other plugin managers.

Features

Manually start gpg-agent in case it's used as agent for SSH.

Set the startup TTY and X-DISPLAY variables to direct future pinentry invocations to another screen. (The settings are needed when gpg-agent is used for SSH auth.)

On remote machine (SSH connection), force ncurses-based prompt for paraphrase input.

The plugin also remove the agent socket when logout from SSH, cause overwriting an existing socket file in remote forwarding is disabled by default.

The plugin is designed as a replacement for existing gpg plugins from Oh-My-ZSH and Prezto, both of which are outdated:

  1. gpg command auto starts the gpg-agent. There's no need to start it manually unless gpg-agent is used for SSH
  2. GPG_AGENT_INFO is removed in GnuPG 2.1.0
  3. New subcommands are introduced to detect socket location

Installation

The only ZSH plugin manager solves the time-consuming init for nvm, nodenv, pyenv, rvm, rbenv, thefuck, fasd, etc, with its amazing async Turbo Mode.

zinit ice wait'1' lucid
zinit light laggardkernel/zsh-gpg-agent

The only framework does optimizations in plugins with sophisticated coding skill:

mkdir -p ${ZDOTDIR:-$HOME}/.zprezto/contrib 2>/dev/null
git clone https://github.com/laggardkernel/zsh-gpg-agent.git ${ZDOTDIR:-$HOME}/.zprezto/contrib/gpg-agent

Settings

Socket Location

Using gpgconf --list-dir agent-socket to get the socket location is not the fastest, but the most compatible. To speed up the location detection for sockets, you may wanna set the following variables before the plugin is loaded.

if [[ $OSTYPE == darwin* ]]; then
  _GPG_AGENT_SOCK="${HOME}/.gnupg/S.gpg-agent"
  _GPG_AGENT_SSH_SOCK="${HOME}/.gnupg/S.gpg-agent.ssh"
elif [[ $OSTYPE == linux* ]]; then
  _GPG_AGENT_SOCK="${XDG_RUNTIME_DIR}/.gnupg/S.gpg-agent"
  _GPG_AGENT_SSH_SOCK="${XDG_RUNTIME_DIR}/.gnupg/S.gpg-agent.ssh"
fi

Auto Start

gpg-agent auto start and SSH_AUTH_SOCK export could be controlled by zstyle settings,

zstyle ':prezto:module:gpg-agent:auto-start' local 'yes' # default yes
zstyle ':prezto:module:gpg-agent:auto-start' remote 'no' # default no

Note: gpg-agent autostart is disabled by default on remote machine.

TODO

  • Cache ssh-agent-support detection for GnuPG

License

The MIT License (MIT)

Copyright (c) 2021 laggardkernel

About

Use gpg-agent as an agent for SSH

License:MIT License


Languages

Language:Shell 100.0%