大网数据广告活动
服务器运维问答

How to check if SSH agent forwarding is running, from the remote server?

· 52CE 我爱测

Locally, I've turned on the SSH agent and I've added my key: $ eval $(ssh-agent) Agent pid 80 $ ssh-add Identity added: /c/Users/...../.ssh/id_rsa (.....@........) In my ~/.ssh/config , I have this: Host example User root HostNam…

问题原文

原帖链接 · dodov · CC BY-SA 4.0

Locally, I've turned on the SSH agent and I've added my key:

  1. $ eval $(ssh-agent)
    Agent pid 80
    
  2. $ ssh-add
    Identity added: /c/Users/...../.ssh/id_rsa (.....@........)
    

In my ~/.ssh/config, I have this:

Host example
    User root
    HostName 123.45.678.912
    ForwardAgent yes

Once I run ssh example, I am successfully connected and if I make a remote test connection to GitHub, I can see that I'm authenticated using my forwarded key:

root@example:~# ssh -vT [email omitted]
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1j  16 Feb 2021
...
debug1: Will attempt key: .....@........ RSA SHA256:abc123/123456abcdefghi/abcdefg12+abcdefghij agent
...
debug1: Offering public key: .....@........ RSA SHA256:abc123/123456abcdefghi/abcdefg12+abcdefghij agent
debug1: Server accepts key: .....@........ RSA SHA256:abc123/123456abcdefghi/abcdefg12+abcdefghij agent
debug1: Authentication succeeded (publickey).
...
Hi ......! You've successfully authenticated, but GitHub does not provide shell access.

Is there a way to determine, on the remote machine, if agent forwarding works, without such a test connection?

This answer suggested using $SSH_AGENT_PID, but it's empty, on both the local and remote machine.

已采纳解答

原帖链接 · asktyagi · CC BY-SA 4.0

If the variable is not set on server, it means that agent forwarding is not working

Forwarding working example.

$ echo "$SSH_AUTH_SOCK"
# Print out the SSH_AUTH_SOCK variable
> /tmp/ssh-6hNGMk10AZC/agent.89543

Not working example

$ echo "$SSH_AUTH_SOCK"
# Print out the SSH_AUTH_SOCK variable
> [No output]
$ ssh -T [email omitted]
# Try to SSH to github
> Permission denied (publickey).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-11-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。