使我的 ssh 密钥自动过期

Spa*_*Hit 9 ssh

我有时ssh用来连接到远程机器。一旦我输入密码,我可以ssh不用密码再次使用,但即使我很长时间回来,它仍然不询问我,因为密钥已缓存。我可以ssh-add -D从缓存中删除密钥,但我希望在 1 小时后自动发生。我怎样才能做到这一点?

Mar*_*mo- 11

缓存您的 ssh 密钥的程序是 ssh-agent 程序,如果您查看手册页,您可以看到此 relivent 选项:

-t life  Set a default value for the maximum lifetime of identities added
         to the agent.  The lifetime may be specified in seconds or in a
         time format specified in sshd_config(5).  A lifetime specified
         for an identity with ssh-add(1) overrides this value.  Without
         this option the default maximum lifetime is forever.
Run Code Online (Sandbox Code Playgroud)

您可以在启动程序中编辑 ssh-agent 程序。转到System > Preferences > Startup Programs,查找SSH Key Agent并附-t 3600加到 comman。这将使您的密钥在一小时内过期。

替代文字

您需要重新启动会话(注销并重新登录)才能生效。您也可以为您的 gpg 密钥做类似的事情,也可以在代理程序中设置,该程序可以以相同的方式启动(但默认情况下未安装),以防您厌倦输入您的 gpg 密码短语用于打包构建或发送电子邮件。