关于 SSH 密钥的通行短语
使用 SSH 密钥时,如果攻击者获得你计算机的访问权限,便可以访问使用该密钥的每个系统。 要添加额外的安全层,可以向 SSH 密钥添加密码。 为避免每次连接时都输入通行短语,可以将通行短语安全地保存在 SSH 代理中。
添加或更改密码
通过输入以下命令,您可以更改现有私钥的密码而无需重新生成密钥对:
$ ssh-keygen -p -f ~/.ssh/id_ed25519
> Enter old passphrase: [Type old passphrase]
> Key has comment 'your_email@example.com'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [Repeat the new passphrase]
> Your identification has been saved with the new passphrase.
如果您的密钥已有密码,系统将提示您输入该密码,然后才能更改为新密码。
在密钥链中保存密码
在 Mac OS X Leopard 上通过 OS X El Capitan,这些默认私钥文件将自动处理:
- .ssh/id_rsa
- .ssh/identity
初次使用密钥时,系统将提示您输入密码。 如果选择使用密钥链保存密码,则无需再次输入密码。
否则,您可在将密钥添加到 ssh-agent 时在密钥链中存储密码。 有关详细信息,请参阅“生成新的 SSH 密钥并将其添加到 ssh-agent”。