ssh - 通过 ssh-tunnel 从本地计算机连接到远程服务器

标签 ssh ansible

我正在我的机器上运行 Ansible。而且我的机器没有 ssh 访问远程机器的权限。来自本地计算机的端口 22 连接被研究所防火墙阻止。但我可以访问一台机器(ssh-tunnel),通过它我可以登录到远程机器。现在有没有一种方法可以让我们从本地机器在远程主机上运行 ansible playbook。

在某种程度上,可以通过 ssh-tunnel 让 Ansible/ssh 连接到远程计算机。但不完全登录到 ssh-tunnel。连接将通过隧道。

另一种方法是我可以在 ssh-tunnel 上安装 ansible,但这不是所需的并从那里运行播放。但这不是一个理想的解决方案。

请告诉我这是否可行。

最佳答案

有两种方法可以实现此目的,无需在 ssh 隧道计算机上安装 Ansible。

解决方案#1:

在您的库存中使用这些变量:

[remote_machine]
remote ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user='username' ansible_ssh_private_key_file='/home/user/private_key'

希望您理解以上参数,如果需要帮助请在评论中询问

解决方案#2:

创建~/.ssh/config文件并添加以下参数:

####### Access to the Private Server through ssh-tunnel/bastion ########

Host ssh-tunnel-server
    HostName x.x.x.x
    StrictHostKeyChecking no
    User username
    ForwardAgent yes

Host private-server
  HostName y.y.y.y
  StrictHostKeyChecking no
  User username
  ProxyCommand ssh -q ssh-tunnel-server nc -q0 %h %p

希望对您有所帮助,如果您需要任何帮助,请随时询问

关于ssh - 通过 ssh-tunnel 从本地计算机连接到远程服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897299/

相关文章:

bash - 如果 heredoc 命令失败,如何退出脚本

C# 在使用 SSH Ftp 时出现 "DER length is ' 9 5' and cannot be more than 4 bytes"错误

ansible - 如何使用 ansible 仅将通过相同键路径标识的每个文件存储列表的唯一项目加载到单个变量中?

Ansible:如何获取数组中的值在条件下使用

Hadoop 多节点集群,root 权限被拒绝

macos - 尝试安装 Hadoop - 出现权限被拒绝错误

Ansible 在变量模板中使用任务返回变量

docker - Ansible 对 docker 模块的支持

linux - 如何处理永无休止的循环linux命令-ansible

linux - CHECK_NRPE : Error - Could not complete SSL handshake AND cannot SSH into box or access it locally