在本地,我已经打开了 SSH 代理并且添加了我的密钥:
-
$ eval $(ssh-agent) Agent pid 80
-
$ ssh-add Identity added: /c/Users/...../.ssh/id_rsa (.....@........)
在我的 中~/.ssh/config
,我有这个:
Host example
User root
HostName 123.45.678.912
ForwardAgent yes
一旦运行ssh example
,我就成功连接了,如果我与 GitHub 建立远程测试连接,我可以看到我使用转发的密钥进行了身份验证:
root@example:~# ssh -vT [email protected]
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.
有没有办法确定,在远程机器上,如果代理转发有效,则无需这样的测试连接?
这个答案建议使用$SSH_AGENT_PID
,但它是空的,无论是在本地还是远程机器上。
答案1
如果服务器上未设置该变量,则表示代理转发不起作用
转发工作示例。
$ echo "$SSH_AUTH_SOCK"
# Print out the SSH_AUTH_SOCK variable
> /tmp/ssh-6hNGMk10AZC/agent.89543
不起作用的示例
$ echo "$SSH_AUTH_SOCK"
# Print out the SSH_AUTH_SOCK variable
> [No output]
$ ssh -T [email protected]
# Try to SSH to github
> Permission denied (publickey).