Can I reduce the number of two-factor authentication prompts for SSH connections?

On Linux, the OpenSSH connection-sharing options ControlMaster and ControlPersist allow an authenticated SSH connection to be reused for a specified period.

Add the following settings to ~/.ssh/config.

Two-factor authentication is required as usual for the first connection.
After the last SSH session is closed, the authenticated connection remains active for up to 60 minutes and can be reused for subsequent connections during that period.

Notes

  • ・This FAQ applies to Linux environments. On Windows, please use a Linux environment such as WSL.
  • We recommend setting the ControlPersist duration to no more than 60 minutes.
  • On shared computers, the authenticated SSH connection remains active in the background. Therefore, the use of ControlPersist is not recommended.
  • ・Two-factor authentication is required again after the retention period expires or the retained connection is terminated.

 

Supplement: Terminating a Persistent SSH Connection

If you want to terminate an SSH connection maintained by ControlPersist before the persistence period expires,
simply closing the terminal window may leave the authenticated SSH connection running in the background.

To explicitly terminate the persistent connection, shut down the Linux environment you are using or run the following command:

This command terminates the persistent SSH connection to the specified host.
Two-factor authentication will be required again the next time you connect via SSH.