I use OS X and a private SSH key stored in a Yubikey to SSH to remote servers. Each time after my Mac sleeps and wakes, I need to run gpg-connect-agent updatestartuptty /bye
. This answer said I can put this command in ~/.ssh/config
like so
Match host * exec "gpg-connect-agent updatestartuptty /bye"
But this doesn't work because I need to set the GPG_TTY
env var in the context of this exec
to my current shell's tty
value. I use fish shell and have this in ~/.config/fish/config.fish
set -x GPG_TTY (tty)
But when the ssh exec
runs, tty returns not a tty
. These are all my env vars.
cat ~/.ssh/config
...
Match host * exec "env > /tmp/t"
...
[run ssh some-host command]
cat /tmp/t
PWD=/Users/dxia
COLORFGBG=12;8
LC_TERMINAL=iTerm2
LOGNAME=dxia
GPG_TTY=not a tty
LANG=en_US.UTF-8
XPC_FLAGS=0x0
TERM=xterm-256color
TMPDIR=/var/folders/x1/f9sjnv7j43z73sdv5lsk3r8h0000gp/T/
EDITOR=/usr/bin/vim
COLORTERM=truecolor
LC_TERMINAL_VERSION=3.4.10
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x1F6:0x0:0x0
HOME=/Users/dxia
ITERM_PROFILE=Default
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.4.10
DISPLAY=/private/tmp/com.apple.launchd.6iiZkY4Tos/org.xquartz:0
USER=dxia
SHLVL=1
COMMAND_MODE=unix2003
TERM_SESSION_ID=w0t0p1:5945A63C-850F-4DCF-A605-F72860D9D72C
__CFBundleIdentifier=com.googlecode.iterm2
SHELL=/usr/local/bin/fish
ITERM_SESSION_ID=w0t0p1:5945A63C-850F-4DCF-A605-F72860D9D72C
PATH=/opt/homebrew/sbin:/opt/homebrew/bin:/Users/dxia/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/sbin:/usr/local/opt/fzf/bin:/opt/homebrew/opt/fzf/bin:/Users/dxia/.jenv/shims:/Users/dxia/.jenv/shims:/Users/dxia/.rbenv/shims:/Users/dxia/google-cloud-sdk/bin
SSH_AUTH_SOCK=/Users/dxia/.gnupg/S.gpg-agent.ssh
How can I get Match host * exec ...
to inherit the tty? Or is there an altogether better way to make OS X work with Yubikey + SSH after sleep/wake?