← 返回命令列表

Linux command

ssh-agent 命令

网络

需要网络或远程资源。

常用示例

Start ssh-agent

eval $(ssh-agent)

Start agent in background

ssh-agent -s

Start with C-shell

ssh-agent -c

Kill the running agent

ssh-agent -k

Run a command

ssh-agent [command]

Set key lifetime

ssh-agent -t [1h]

说明

ssh-agent is a program that holds private keys used for SSH public key authentication. The agent runs in the background and provides keys to SSH clients without requiring passphrase re-entry. Keys are added to the agent using ssh-add. Once added, the agent responds to authentication requests from SSH connections, including forwarded agent connections from remote hosts. The agent outputs shell commands to set environment variables (SSH_AUTH_SOCK and SSH_AGENT_PID). These must be evaluated in the shell using eval $(ssh-agent) to enable communication between SSH clients and the agent.

参数

-s
Generate Bourne shell commands on stdout.
-c
Generate C-shell commands on stdout.
-k
Kill the current agent (using SSH_AGENT_PID).
-d
Debug mode (don't fork).
-D
Foreground mode without debug output.
-a _SOCKET_
Bind to specified Unix socket instead of random.
-t _LIFE_
Default maximum lifetime for added keys (e.g., 1h, 30m).

FAQ

What is the ssh-agent command used for?

ssh-agent is a program that holds private keys used for SSH public key authentication. The agent runs in the background and provides keys to SSH clients without requiring passphrase re-entry. Keys are added to the agent using ssh-add. Once added, the agent responds to authentication requests from SSH connections, including forwarded agent connections from remote hosts. The agent outputs shell commands to set environment variables (SSH_AUTH_SOCK and SSH_AGENT_PID). These must be evaluated in the shell using eval $(ssh-agent) to enable communication between SSH clients and the agent.

How do I run a basic ssh-agent example?

Run `eval $(ssh-agent)` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -s do in ssh-agent?

Generate Bourne shell commands on stdout.