memiah.autossh

AutoSSH

一个 Ansible 角色,用于安装和配置多个 autossh 连接, 通过 SSH 从本地服务器转发端口到远程服务器。

需求

我们假设 SSH 用户已经存在,并且拥有访问远程服务器的正确权限。相应的 SSH 密钥也必须在本地服务器上存在(/root/.ssh/id_rsa 或根据每个连接配置定义)。

角色变量

可用变量如下所示,以及默认值(见 defaults/main.yml):

autossh_connections:
  - id: "example" # 简单唯一的连接标识符(字符: "a-z,0-9,-")。
    user: "" # 用于连接远程服务器的用户名。
    server: "" # 远程服务器的 IP 或主机名。
    server_key_type: "" # 远程服务器的密钥类型,默认为 autossh_default_server_key_type。(可选)
    local_port: "" # 要转发的本地端口。
    dest_server: "" # 在远程服务器上使用的 IP 或主机名,默认为 autossh_default_dest_server。(可选)
    dest_port: "" # 在远程服务器上要连接的端口。
    identity_file: "" # SSH 私钥的路径,默认为 autossh_default_ssh_key_path。(可选)

每个连接添加一组 SSH 连接属性。可以在此列出多个连接。

autossh_path: "/usr/bin/autossh"

autossh 的路径。

autossh_ssh_dir: "/root/.ssh"

存储 SSH 配置的目录。

autossh_systemd_dir: "/etc/systemd/system/"

systemd 系统目录的路径。

autossh_known_hosts_file: "{{ autossh_ssh_dir }}/known_hosts"

已知主机文件的路径。

autossh_default_server_key_type: "ecdsa"

远程服务器的默认密钥类型。通过在 autossh_connections 列表中使用 server_key_type 选项为单个连接覆盖此值。

autossh_default_dest_server: "127.0.0.1"

在远程服务器上使用的默认 IP / 主机名,这很可能是 localhost / 127.0.0.1。通过在 autossh_connections 列表中使用 dest_server 选项为单个连接覆盖此值。

autossh_default_identity_file: "/root/.ssh/id_rsa"

读取用于公钥身份验证的身份(私钥)的文件路径。默认情况下为协议版本 2 的 /root/.ssh/id_rsa。通过在 autossh_connections 列表中使用 identity_file 选项为单个连接覆盖此值。

依赖关系

无。

示例剧本

- hosts: servers
  vars_files:
    - vars/main.yml
  roles:
     - { role: memiah.autossh }

vars/main.yml

autossh_connections:
  - id: "example"
    user: "username"
    server: "remote.server"
    local_port: "33061"
    dest_port: "3306"

将本地端口 33061 转发到 remote.server 上的端口 3306,以 [email protected] 的身份通过 SSH 连接。

这将创建一个名为 autossh-example.service 的新服务 *(autossh-{id}.service)*,可以通过 systemctl 管理:

systemctl status autossh-example.service
systemctl restart autossh-example.service
...

许可证

MIT / BSD

作者信息

该角色于 2016 年由 Memiah Limited 创建。

关于项目

Install and configure autossh connections on RedHat systems.

安装
ansible-galaxy install memiah.autossh
许可证
Unknown
下载
134
拥有者