↑ ↓ select, Enter open, Esc close

Start ssh-agent and load a key for a limited time

Adjust the values, the command updates live
user@server
eval "$(ssh-agent -s)" && ssh-add -t 4h ~/.ssh/id_ed25519_server

Starts an SSH agent for the current shell and loads the key after you enter the passphrase once. With -t the key is removed automatically after the given time. ssh-add -l shows the loaded keys, ssh-add -D removes all of them.

Note: On desktops an agent is usually already running, in which case the ssh-add part is enough.

Also searched as

  • how to add ssh key to ssh-agent
  • ssh-add key with timeout
  • enter ssh passphrase only once

Related one-liners

All in SSH

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.