AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 717129
Accepted
mralexgray
mralexgray
Asked: 2015-08-27 18:44:34 +0800 CST2015-08-27 18:44:34 +0800 CST 2015-08-27 18:44:34 +0800 CST

如何显示主机/配置/默认 ssh “配置”?

  • 772

根据我的ssh_config档案...

配置数据解析如下:

  1. 命令行选项
  2. 用户特定文件
  3. 系统范围的文件

话虽如此,(是的,我知道,我可以搜索man ssh_configANDman ssh和(希望)记录默认值).. 对于所有当前设置,我如何“打印”活动配置。例如,类似...

ssh -o Tunnel=ethernet servername -p 2210 --print-config

SSH-2.0-OpenSSH_7.0
 Command Line Options
   Port 2210
   Host servername
 Command Line Configurations
   Tunnel Ethernet
 Config File
   ...
 SSH Defaults
   ...
   AddressFamily any (???)
   BatchMode no
   ...

这会让你明确地知道设置了什么,以及为什么。我特别指出,因为它是没有记录默认值AddressFamily的配置选项的完美示例。从...man ssh_config

指定连接时使用的地址族。有效参数是any, inet(仅使用 IPv4)或inet6(仅使用 IPv6)。

啊! 感谢任何建设性的建议(不仅仅是一堆RTFM)。?

ssh
  • 2 2 个回答
  • 26404 Views

2 个回答

  • Voted
  1. Best Answer
    Jakuje
    2015-08-28T00:35:28+08:002015-08-28T00:35:28+08:00

    最近的 openssh 中有一个-G选项,其行为方式与-T服务器端类似。

    -G 使 ssh 在评估 Host 和 Match 块后打印其配置并退出。

    通过调用ssh -G host,您将获得用于连接到特定主机的选项,这有助于调试ssh_config.

    此外,设置更详细的日志级别 ( -vvv) 有助于调试配置解析器。

    • 56
  2. Ti Strga
    2022-06-16T11:35:38+08:002022-06-16T11:35:38+08:00

    唯一潜在的缺点-G是它会转储给定目标主机的整个变量集,这对脚本很有用,但在视觉上排序可能有点混乱。

    我拼凑了一个又快又脏的 AWK 脚本来满足我的需要;给它一个在Host一行中找到的名称片段,它将打印在.ssh/config文件中找到的配置块。请记住,(1)主机行可以有多个条目,(2)这确实假设配置行将为每个主机块缩进。此外,该脚本不会打印出配置文件中指定的任何全局选项,因为我不想要这些。

    #!/usr/bin/gawk -f
    #
    # Given a ~/.ssh/config file that looks like
    #
    #    SettingOne foo
    #    SettingTwo bar
    #
    #    Host hostX hostY
    #      SettingBlah yes
    #      SettingBlurg no
    #
    #    Host hostZ
    #      SettingBlurg no
    #
    # then "print_ssh_block hostY" will print out the corresponding Setting block,
    # which is considerably easier for a human to read than the output of
    # "ssh -G hostY".
    
    BEGIN {
        if (ARGC != 2) {
            print "Usage:  print_ssh_block host_fragment"
            exit 1
        }
    
        # ARGV[0] is the script file itself
        # ARGV[1] is the string fragment to later match in Host lines; we don't
        # want to actually process it as a filename...
        hostfrag = ARGV[1]
        # ...so we replace it with the filename of SSH's config, which we DO want
        # to process with patterns.
        ARGV[1] = ENVIRON["HOME"] "/.ssh/config"
        ARGC = 2
        inHostBlock = 0
    }
    
    /#/ { next }
    
    /^[Hh][Oo][Ss][Tt] / {
        # skip $1, since that's "Host"
        for (i = 2; i <= NF; i++) {
            # $i is the individual host; if it matches the script argument,
            # set or clear the flag appropriately
            inHostBlock = ($i ~ hostfrag) ? 1 : 0
            if (inHostBlock) break
        }
    }
    
    # When not in a matching host block, skip the indented lines.
    inHostBlock == 0 && /^[[:space:]]/ { next  }
    
    # When inside a matching host block, clear the flag as soon as we reach an
    # empty line.
    inHostBlock == 1 && /^$/  { inHostBlock = 0 }
    
    # When inside a matching host block, print every line we encounter.
    inHostBlock == 1          { print }
    

    可以对此进行大约无限的改进。真正的 AWK 大师大概可以用大约五行来编写它。

    • 0

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve