ssh - ssh proxycommand -W, nc, exec nc 有什么区别

标签 ssh

我看过一些关于 .ssh/config 和 proxycommand 的博客

现在下一个命令之间有什么区别
ProxyCommand ssh proxyserver -W [%h]:%pProxyCommand ssh proxyserver nc -q0 %h %p 2> /dev/nullProxyCommand ssh proxyserver exec nc -q0 %h %p 2> /dev/null
其中一些命令在某些机器上有效,而在其他机器上无效。

最佳答案

以下是我的理解:

  • ProxyCommand ssh proxyserver -W [%h]:%p
  • -W选项内置于 OpenSSH 的新(er)版本中,因此这仅适用于具有最低版本(5.4,除非您的发行版向后移植任何功能;例如,RHEL6 OpenSSH 5.3p1 包含此功能)的机器。根据发行说明:http://www.openssh.com/txt/release-5.4

    Added a 'netcat mode' to ssh(1): "ssh -W host:port ..." This connects stdio on the client to a single port forward on the server. This allows, for example, using ssh as a ProxyCommand to route connections via intermediate servers.

  • ProxyCommand ssh proxyserver nc -q0 %h %p 2> /dev/null
  • 之前-W选项可用,我们使用了 nc (或 netcat)实用程序。 nc允许您将 TCP 和 UDP 数据包转发到指定的(备用)位置,其行为与 ssh -W 基本相同(因为 ssh -W 是仿照 nc 建模的)。为了使此变体起作用,中间宿主需要nc安装和选件 AllowTcpForwarding必须在主机的 sshd_config 中启用(默认值:yes)。选项 -q0nc是(应该是)用于消除错误,但我找不到这是引入的哪个版本。 (注意:2> /dev/null 可能会导致 ssh 错误,但可以使用 ssh -q 代替。)
  • ProxyCommand ssh proxyserver exec nc -q0 %h %p 2> /dev/null
  • 这与第二个变体非常相似,除了您调用的是 shell 的内置函数 exec .我不确定,但我相信包含或排除 exec 之间没有区别来自 ProxyCommand ;这种变化应该在上述变化的任何地方起作用。例如,Bash 手册是这样说的:

    exec [-cl] [-a name] [command [arguments]]

    If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command. If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command. This is what login(1) does. The -c option causes command to be executed with an empty environment. If -a is supplied, the shell passes name as the zeroth argument to the executed command. If command cannot be executed for some reason, a non-interactive shell exits, unless the shell option execfail is enabled, in which case it returns failure. An interactive shell returns failure if the file cannot be executed. If command is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1.

  • 关于ssh - ssh proxycommand -W, nc, exec nc 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22635613/

    相关文章:

    git - 如何通过ssh git clone而无需输入密码?

    linux - 无法通过 SSH 保留最新的 5 个文件夹并删除较旧的文件夹

    java - 使用 JSch 运行 here-doc 命令

    ssh - 如何在windows机器中生成known_host文件

    Python 连接到 ssh mysql 服务器

    ssh - Google Compute Engine-如果禁用ssh端口,则备用登录虚拟机实例

    python - 通过 cron 调用时,MQTT Python 无法启动 Bash 脚本

    ssh - Google云引擎,两个centos7实例之间的ssh失败

    git - 获取 Visual Studio 2017 以使用 ssh-agent/ssh-add for git

    java - 通过 ssh 运行 mysql 命令