OpenSSH: ssh-add / ssh-agent Command Set Maximum Lifetime In Seconds

The lifetime of the ssh-agent process, and the keys it holds, can be set by using the -t or -t <seconds> option when starting the ssh-agent process.

Here’s an example of how to start the ssh-agent process with a maximum lifetime of 3600 seconds (1 hour):

# Start the ssh-agent process with a lifetime of 3600 seconds
eval "$(ssh-agent -t 3600)"

In this example, the ssh-agent process is started with the -t 3600 option, which sets the maximum lifetime of the agent to 3600 seconds. The output of the ssh-agent command is evaluated using the eval command, which sets the environment variables required by the ssh-agent process.

Once the ssh-agent process is running, you can add keys to it using the ssh-add command, and those keys will be automatically removed from the ssh-agent when the maximum lifetime is reached.

Note that if you want to change the maximum lifetime of the ssh-agent process after it has been started, you will need to stop the existing ssh-agent process and start a new one with the desired lifetime.

Leave a Comment