Edited at

macOS SierraでSSH鍵のパスフレーズの件

More than 1 year has passed since last update.

今日SierraにアップデートしたところSSHの鍵を毎回聞くようになりました。

簡単にググったところ割とトラブルになってるようですが、海外のサイトでSSHのconfigに追加すればいいという記載があり、その通りにすればできたので、備忘録がてら。


ssh_config

man ssh_config

と実行し終わり頃を見ると下記のように書いてあります。

UseKeychain

On macOS, specifies whether the system should search for passphrases in the user's keychain when
attempting to use a particular key. When the passphrase is provided by the user, this option also speci-
fies whether the passphrase should be stored into the keychain once it has been verified to be correct.
The argument must be ``yes'' or ``no''. The default is ``no''.

追加でAddKeysToAgentも追加します。これを追加しておかないとForwardAgentが有効に動作しませんでした。

     AddKeysToAgent

Specifies whether keys should be automatically added to a running ssh-agent(1). If this option is set to ``yes'' and a key is loaded from
a file, the key and its passphrase are added to the agent with the default lifetime, as if by ssh-add(1). If this option is set to
``ask'', ssh will require confirmation using the SSH_ASKPASS program before adding a key (see ssh-add(1) for details). If this option is
set to ``confirm'', each use of the key must be confirmed, as if the -c option was specified to ssh-add(1). If this option is set to
``no'', no keys are added to the agent. The argument must be ``yes'', ``confirm'', ``ask'', or ``no''. The default is ``no''.

defaultがnoのようなので.ssh/configに以下のように追記します。(どこでもいいと思いますが、自分は Host * に追加しました)

 Host *

ServerAliveInterval 1200
ServerAliveCountMax 12
TCPKeepAlive yes
Compression yes
+ AddKeysToAgent yes
+ UseKeychain yes
GSSAPIAuthentication no
UseRoaming no


参考にしたページ

http://apple.stackexchange.com/questions/254468/macos-sierra-doesn-t-seem-to-remember-ssh-keys-between-reboots