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 / 问题 / 927689
Accepted
Andy
Andy
Asked: 2018-08-24 06:33:38 +0800 CST2018-08-24 06:33:38 +0800 CST 2018-08-24 06:33:38 +0800 CST

为 Ansible 设置 SSH 跳转框 - 无法连接

  • 772

我正在尝试使用 Ansible 部署到没有公共 IP 地址的 AWS 主机。我可以通过 ssh 手动访问主机到一个跳转框,然后在那个盒子上 ssh 到私人机器上,比如my machine-->bastion-->private server

我不认为我可以使用 Ansible 原生支持,因为这个剧本使用与其他剧本共享的角色。这些角色依赖于特定的库存组。如果我进行了设置,group_vars那么这将破坏将其部署到非 AWS 基础设施的剧本。

我的 ssh 配置文件如下所示:

# Servers in availability zone A
    Host 10.0.0.*
      ProxyCommand ssh -W %h:%p bastion.example.com
      IdentityFile ~/.ssh/key.pem

# Servers in availability zone B
Host 10.0.1.*
  ProxyCommand ssh -W %h:%p bastion.example.com
  IdentityFile ~/.ssh/key.pem

# The bastion host itself
Host bastion.example.com
  User ubuntu
  IdentityFile ~/.ssh/key.pem
  ControlMaster auto
  ControlPath ~/.ssh/ansible-%r@%h:%p
  ControlPersist 5m

请注意,堡垒和私人服务器的密钥相同。

当我尝试ssh 10.0.0.175 -F /tmp/aws_bastion_ssh_config -vvv得到以下输出时:

    (venv) andrew@dell:~/projects/ansible-playbooks$ ssh 10.0.0.175 -F /tmp/aws_bastion_ssh_config -vvv
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /tmp/aws_bastion_ssh_config
debug1: /tmp/aws_bastion_ssh_config line 6: Applying options for 10.0.0.*
debug1: Executing proxy command: exec ssh -W 10.0.0.175:22 bastion.example.com
debug1: permanently_drop_suid: 1000
debug1: key_load_public: No such file or directory
debug1: identity file /home/andrew/.ssh/key.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/andrew/.ssh/key.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
Permission denied (publickey).
ssh_exchange_identification: Connection closed by remote host

我怎样才能让它工作?

我需要把钥匙放在跳箱上吗?我该如何配置?

编辑:更多信息:-澄清当ssh bastion.example.com -F /tmp/aws_bastion_ssh_config我到达堡垒服务器时,我可以从跳转框连接到私人机器。我已将密钥复制到该服务器,当ssh [email protected] -i ~/.ssh/key.pem我连接到私人机器时。理想情况下,我不希望在跳转盒上有钥匙,我只是把它放在那里以确保网络正常运行。

ssh
  • 1 1 个回答
  • 4347 Views

1 个回答

  • Voted
  1. Best Answer
    anx
    2018-08-24T10:24:12+08:002018-08-24T10:24:12+08:00

    您使用 ProxyCommand 所做的是启动两个完全独立的 ssh 命令。

    1. 即尝试使用代理对 10.0.0.175 进行身份验证,因此您不需要堡垒上的密钥和配置。
    2. 提供代理的那个,只需要能够对堡垒进行身份验证。

    您对 1. 的命令运行良好,但您没有看到 2. 的调试输出。由于您使用了可解析的 TLD 并且其他所有内容都是通用配置,因此 2. 没有出现任何错误 - 但它没有按照您的意愿行事,因为它是从未在您的配置中提供IdentityFileandUser选项。它正在使用不同的密钥或用户进行身份验证,并被堡垒拒绝(理所当然)。

    为确保 2. 也读取您的配置,请显式传递该选项,如下所示:

    # Servers in availability zone A
    Host 10.0.0.*
      ProxyCommand ssh -vvv -F /tmp/aws_bastion_ssh_config -W %h:%p bastion.example.com
      IdentityFile ~/.ssh/key.pem
    
    # Servers in availability zone B
    Host 10.0.1.*
      ProxyCommand ssh -vvv -F /tmp/aws_bastion_ssh_config -W %h:%p bastion.example.com
      IdentityFile ~/.ssh/key.pem
    
    # The bastion host itself
    Host bastion.example.com
      User ubuntu
      IdentityFile ~/.ssh/key.pem
      ControlMaster auto
      ControlPath ~/.ssh/ansible-%r@%h:%p
      ControlPersist 5m
    

    一切都应该工作。确认:

    ssh -vvv -F /tmp/aws_bastion_ssh_config 10.0.0.175
    

    然后删除-vvv表单 1. 和 2。如果您将您的移动/tmp/aws_bastion_ssh_config到默认位置,-F则可以删除这两个选项(并且 ssh 将读取/etc/ssh/ssh_config and ~/.ssh/config files)

    • 2

相关问题

  • 如何最好地设置 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