- Linux Administration Cookbook
- Adam K. Dean
- 162字
- 2021-07-02 14:24:25
There's more...
If you want to add the agent start command to a script (say .bashrc), you may want to automatically evaluate the environment variables given to you. ssh-agent assumes you're starting it this way.
In the manual page for ssh-agent, you even get this tip.
"There are two main ways to get an agent set up: The first is that the agent starts a new sub‐command into which some environment variables are exported, eg ssh-agent xterm &. The second is that the agent prints the needed shell commands (either sh(1) or csh(1) syntax can be generated) which can be evaluated in the calling shell, eg eval 'ssh-agent -s' for Bourne-type shells such as sh(1) or ksh(1) and eval 'ssh-agent -c' for csh(1) and derivatives."
In practice, this means that it's easiest to start the agent like so:
[vagrant@centos1 ~]$ eval $(ssh-agent)
Agent pid 6896
Here, we're using a Bash sub-shell to start and read the agent's output.