Start ssh-agent from the current shell and apply its SSH_AUTH_SOCK and related settings to that shell.
Which command is appropriate in a Bourne-style shell?
ssh-agent -s prints shell commands; eval executes them in the current shell so SSH_AUTH_SOCK and SSH_AGENT_PID are set there.
Detailed explanation
eval "$(ssh-agent -s)"Correct. It starts the agent and evaluates its environment commands in the current shell.
Correct. It starts the agent and evaluates its environment commands in the current shell.
ssh-agent -s | sshIncorrect. Piping output into ssh does not update the current shell environment.
Incorrect. Piping output into ssh does not update the current shell environment.
export ssh-agent -sIncorrect. export cannot execute a command substitution in that form.
Incorrect. export cannot execute a command substitution in that form.
ssh-add --start-agentIncorrect. ssh-add does not provide a standard agent-start option with that name.
Incorrect. ssh-add does not provide a standard agent-start option with that name.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' 'ssh-agent -s -> shell assignments' 'eval -> apply assignments to current shell'Expected result
ssh-agent -s -> shell assignments
eval -> apply assignments to current shellKey points
- Start the agent
- SSH_AUTH_SOCK
- eval in the current shell
Notes
- Environment: OpenSSH agent起動構文(agent実行なし)
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.