How to start the SSH agent?
How to start the SSH agent?
Run the eval command inside the shell together with the ssh-agent.
eval $(ssh-agent)The ssh-agent command is started manually using eval $(ssh-agent)
. This will initiate the SSH agent and make it available for clients, such as ssh, to use it.
To confirm that the agent is running is by looking at the SSH_AUTH_SOCK environment variable.
Automatic start of SSH agent
Gnome Keyring SSH Agent
When using Gnome, it typically comes with its SSH agent as part of Keyring. This will automatically load any files in ~/.ssh when both the secret and public key is available.
Systemd service unit
Create a unit file (/etc/systemd/system/ssh-agent.service):
[Unit]
Description=SSH key agent
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
[Install]
WantedBy=default.target
Then enable it.
systemctl enable --now ssh-agent.service
Start via login profile
When using bash, add the following snippet to your profile ~/.bash_profile to active it upon login.
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval $(ssh-agent -s)
ssh-add
fi
This checks for the presence of the environment variable. If it is empty (-z), then it will start the agent and add keys.