V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
cloudfstrife
V2EX  ›  问与答

一个 gpg-agent 的奇怪表现

  •  
  •   cloudfstrife · Dec 30, 2021 · 1149 views
    This topic created in 1589 days ago, the information mentioned may be changed or developed.

    背景

    我在本地配置了 ssh 使用 gpg-agent 的密钥,即如下配置

    $ cat ~/.gnupg/gpg-agent.conf 
    enable-ssh-support
    
    $ cat ~/.gnupg/sshcontrol
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 3600 confirm
    

    当我使用 ssh 远程连接到远端服务器,在远端服务器使用 git 的时候,貌似也使用本地的 gpg-agent 的密钥来验证了(表现为弹出使用 gpg 密钥的提示框)。

    疑问

    使用 gpg-agent 管理 ssh 密钥时,在远端的操作,会使用本地的密钥进行认证吗?

    3 replies    2022-01-04 12:03:30 +08:00
    cloudfstrife
        1
    cloudfstrife  
    OP
       Dec 30, 2021
    我找到了原因,解释如下:

    ```
    $ cat .ssh/config
    Host 192.168.xx.xxx
    HostName 192.168.xx.xxx
    User xxxxxxxx
    ForwardAgent yes
    ```
    ssh config 中配置了 `ForwardAgent yes` 这里的启用了 agent-forwarding 功能
    如果希望用户对所有远端服务器的连接都启用此功能,可以如下配置`.ssh/config `
    ```
    Host *
    ForwardAgent yes
    ```

    全局启用可以修改 `/etc/ssh/ssh_config`文件中的 `#ForwardAgent no` 改为 `ForwardAgent yes`

    服务端 sshd 配置 `AllowAgentForwarding` 默认为 YES ,所以,远端服务的 ssh 验证被转发到本地的 gpg-agent 来处理了。

    原理非常简单,但是之前没遇到过这种用法,所以……
    wooyuntest
        2
    wooyuntest  
       Jan 2, 2022
    ForwardAgent 实现的。 不仅 ssh 可以转发。gpg 加解密本身 也可以使用本地的 agent ,十分适合 yubikey 这种密钥创建在硬件设备里无法导出的设备做验证的使用场景。
    cloudfstrife
        3
    cloudfstrife  
    OP
       Jan 4, 2022
    @wooyuntest #2 是的,实现原理是转发请求,逐级转发,直到本地 agent 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5176 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 05:42 · PVG 13:42 · LAX 22:42 · JFK 01:42
    ♥ Do have faith in what you're doing.