- Linux Administration Cookbook
- Adam K. Dean
- 156字
- 2021-07-02 14:24:24
How it works...
When we initially run ssh-agent, the agent itself is started in the background, and we're given the necessary environment variables for SSH. After they're set, running SSH will cause it to read these variables.
If we add a couple of -vv flags to SSH, we can see it find our key in the agent:
debug2: key: /home/vagrant/.ssh/id_ed25519 (0x55b11351c410), agent
Without the agent loaded, but with the key present, it looks like this:
debug2: key: /home/vagrant/.ssh/id_ed25519 (0x55dea5015410)
The SSH environment variables are also read by ssh-add, which we used to add our key to the agent. To quote the manual page:
"The authentication agent must be running and the SSH_AUTH_SOCK environment variable must contain the name of its socket for ssh-add to work."
When you've got one key or more in an agent, SSH will try to use these keys to authenticate against remote hosts, removing the need to type your password each time.