- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 /etc/hosts
中定义了一个主机称为 web1
.有一个名为 store
的 docker 容器.
在我的工作站上,我可以通过 ssh 进入机器并执行命令以交互方式进入容器
ssh -t -t web1 docker exec -ti store /bin/bash
正如我所希望的那样,它正确地将我作为 root 直接放入容器中。
但是,我真的很想定义一个名为store
的伪主机。并在我的 ~/.ssh/config
中设置它使用 ProxyCommand
这样的文件所以我可以使用 ssh store
Host store
ProxyCommand ssh -t -t web1 docker exec -ti store /bin/bash
但它失败并出现以下错误:
Bad packet length 218958363.
ssh_dispatch_run_fatal: Connection to UNKNOWN: message authentication code incorrect
Killed by signal 1.
如果我添加 -v 进行一些调试,上面 block 之前的最后两行是
debug1: Authenticating to store:22 as 'user1'
debug1: SSH2_MSG_KEXINIT sent
ssh
进入store
容器而不是仅仅执行抛出该错误的命令,是否正确?如果不是,问题是什么?ssh-store
的别名,还有别的选择吗? ?最终目标是定义一个虚拟主机,我只能说 ssh store
并让它最终出现在 store
中容器 web1
.
编辑:
解决方案:
正如 Jakuje 所指出的,将 ProxyCommand 与 ssh 结合使用将不允许非 ssh 进一步命令。因此,我只是使用别名和可能的 bash 函数来完成它。我已经设置了两者。
同样根据 Jakuje 在 ~/.ssh/config 中的建议
Host web1
RequestTTY yes
在 ~/.bash_aliases 中
alias ssh-store="ssh web1 docker exec -ti store /bin/bash"
所以我可以做ssh-store
并最终进入容器
或者在 ~/.bashrc 中
function ssh-web1 { ssh web1 docker exec -ti $1 /bin/bash; }
所以我可以做ssh-web1 store
并最终进入容器
最佳答案
I think it is trying ssh into the store container instead of just executing the command which is throwing that error, is that correct? If not what is the issue?
是
Is there a way to do this using ProxyCommand without trying to ssh into the container but instead just use the docker exec?
没有。它不是这样工作的。 ProxyCommand
期望其他步骤也是 SSH session ,而不是直接的 bash 提示符。
Is it easy enough to also setup the ssh into the container? We currently aren't doing that as a matter of practice.
我认为这是不必要的开销。但正如此处许多其他问题中所描述的那样,这是可能的。
至少您可以通过在 ~/.ssh/config
中指定 RequestTTY
来摆脱 -t -t
。但其余的必须是 bash 别名或函数(如果你有更多的主机 function 更合适)。
function ssh-docker {
ssh web1 docker exec -ti $1 /bin/bash
}
然后你可以像这样调用它而不考虑容器:
ssh-docker store
您只需将此类函数存储到您的 .bashrc
或您存储别名的位置。
关于linux - 如何正确配置 ssh proxycommand 以运行 docker exec?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34445796/
使用 OpenSSH,我已经设置了我的 /etc/ssh/ssh_config有一个 ProxyCommand所以所有 SSH 连接都通过该代理。 /etc/ssh/ssh_config : Host
由于防火墙限制,我需要能够通过另一台主机连接到另一台主机。我目前能够使用 ProxyCommand 选项成功连接。但现在我需要在连接到目标主机后更改用户,从 user_one 更改为 user_two
我试图配置SSH配置以简化工作流程,但在这里遇到了麻烦。 我有一个跳转主机,需要sudo ssh才能访问所有其他计算机。 我发现,如果我运行ssh -tt jumphost sudo ssh dest
我正在尝试使用计算机 B 上的 key 通过计算机 B 建立隧道,从计算机 A 到计算机 C。我已经共享了从计算机 A 到计算机 B 以及从计算机 B 到计算机 C 的 key 这适用于计算机 A,无
我在使用 ssh proxy 命令时遇到了一些问题。代理上的身份验证工作正常,但是当我想登录到远程主机时它失败了。问题似乎是,代理尝试使用我的本地 rsa_key 登录,而不是使用存储在代理上的 ke
我正在尝试使用 paramiko 通过 SSH 连接到通过另一台计算机隧道传输的计算机在 Python 中,但我遇到了一些奇怪的问题。 我在 /.ssh/config 中的配置文件如下所示: Host
我有一个在防火墙后面的 git 服务器。我可以从家里访问防火墙,但不能访问 git 服务器。但是,我可以从防火墙访问 git 服务器(也就是说,我可以 SSH 到防火墙,然后再从防火墙 SSH 到 g
在我们的环境中,我们有几台服务器在生产中。每次我想搜索某些东西时,它可能在 4 个不同的服务器中的 1 个中。 我正在创建一个脚本来自动执行此搜索,以便我直接知道涉及哪个服务器。 我正在通过 jump
我只是尝试使用 PuTTY 与我的服务器建立 SSH 连接。这些服务器仅允许来自另一个特定服务器(下面示例中的“MySshProxyingServer”)的传入 SSH 连接。 使用 Linux,使用
我有一个网络服务器 WWW1 和一个前置代理 PRX。我使用 SSH ProxyCommand 通过 PRX(私有(private) + 公共(public) IP)连接到 WWW1 的内部 IP(私
我在 /etc/hosts 中定义了一个主机称为 web1 .有一个名为 store 的 docker 容器. 在我的工作站上,我可以通过 ssh 进入机器并执行命令以交互方式进入容器 ssh -t
我打算实现一个 golang 版本的 ssh 客户端来通过堡垒连接到目标服务器。但不幸的是,我在替换 nc 代理时失败了。 在我本地的 ssh 配置: Host bastion HostNam
我看过一些关于 .ssh/config 和 proxycommand 的博客 现在下一个命令之间有什么区别 ProxyCommand ssh proxyserver -W [%h]:%pProxyCo
我想通过另一台使用 ruby 的计算机连接到远程计算机。 这个方案如下: 本地 -> 代理 -> 远程 我有这段代码可以直接访问: require 'net/ssh' Net::SSH.start
我尝试使用 SSH ProxyCommand 通过跳转框连接到服务器时未成功。我的配置在下面,我正在运行这个命令: ssh 10.0.2.54 -F ssh.config -vv Host x.x.x
我有一台服务器(例如,内部服务器)只能从另一台服务器(例如,外部服务器)访问,而不是运行 Node 服务器的服务器。但是, Node 服务器可以到达外部服务器。从命令行使用 ssh 时,我可以使用 P
我是一名优秀的程序员,十分优秀!