最近MacBook系統(tǒng)出了點(diǎn)問(wèn)題,遂重裝了最新的系統(tǒng)macOS Sierra。然鵝,問(wèn)題來(lái)了。以前在終端中使用SSH,若要將key永久保存在本地,只需要執(zhí)行ssh-add -K "KeyPath"命令即可。而現(xiàn)在執(zhí)行此命令雖然依舊能保存成功,但是在“鑰匙串”中找不到保存的SSH密鑰,也就是說(shuō)并沒(méi)有持久化保存到KeyChain中,重啟后測(cè)試,果然ssh密鑰清空了。
研究了一下,原來(lái)問(wèn)題出在系統(tǒng)上,從macOS Sierra 10.12.2以后,SSH的配置選項(xiàng)中多了“UseKeychain”選項(xiàng),在man ssh_config頁(yè)面中有這樣的介紹:
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 specifies whether the passphrase should be stored
into the keychain once it has been verified to be correct. The
argument must beyes'' orno''. The default is ``no''.
要解決這個(gè)問(wèn)題,就要借助于UseKeychain選項(xiàng)。在~/.ssh/config文件中添加下面這段話,問(wèn)題就可以解決了:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa