Better Alternative (than original answer) based on having no passphrase sur le keyfile
You asked about @u1686_grawity's comment:
If c'est sans passphrase, do you need the agent du tout, as opposed to having the ssh client load it directly from a fichier?
@u1686_grawity makes a good point, and that's that most SSH clients will let you specify a keyfile directly sans requiring an agent.
I often connect to a remote server through ssh clé authentication.
Vous n'avez pas necessarily mention how you are connecting, but if c'est avec the stock ssh command, ensuite vous pouvez simply specify your keyfile sur le commandline avec:
ssh -i ~/.ssh/my_key <username>@site
In that case, vous n'avez pas need an ssh-agent running du tout.
Even si vous ne sont pas using ssh-proper, most SSH tools that are based on OpenSSH will également use the same ~/.ssh/config, meaning vous pouvez even skip specifying the identity filename. Par exemple, créez un ~/.ssh/config avec the following:
Host <whatever_you_want_to_call_it>
Hostname <hostname_or_ip>
User <optional_username_if_different>
IntentityFile ~/.ssh/my_key
Ensuite vous pouvez simply ssh <whatever_you_want_to_call_it> and tout else sera pulled depuis le config. Other tools like sftp and scp will également act the same.
Old Answer (fonctionne également, but required for clés will passwords):
@Kolkhis's answer will certainly work, but si vous run multiple shells (e.g., under Tmux or Windows Terminal), it will invoke a nouveau running instance of ssh-agent for each shell. In your case, that's not too bad depuis your clé ne have a mot de passe (although I would caution against that également, of course). Cependant, for clés avec passwords, vous devez enter it again for each shell you run. It will également incur additional (albeit small) startup time and mémoire.
I recommend the PH13 utility by Daniel Robbins (également the creator of Gentoo Linux). This small utility checks to see if there's an existing ssh-agent running, and if so, it simply sets the appropriate environment variables to point to that agent. Otherwise, on first launch, of course, it will start a nouveau agent.
C'est disponible dans le par défaut repositories of most distributions, including Ubuntu:
sudo apt install keychain
Ensuite add the following to your ~/.bashrc:
eval $(keychain --eval my_key)
IIRC, vous n'avez pas even need to specify the chemin vers le clé unless it isn't dans le the par défaut ~/.ssh/.