株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

作業マシンはCentOS7.9

インストール

sudo yum -y install epel-release
sudo yum -y install autossh

接続用ユーザーを作成

sudo groupadd nogroup
sudo useradd -g nogroup -s /bin/bash -m tunnel

sshconfigを作成

Host vamdemic.*
  User root
  Port 22
  ForwardAgent yes

Host            vamdemic.vps
  HostName      123.123.123.123
  RemoteForward  10022 localhost:22
  RemoteForward  20022 192.168.10.14:22
  RemoteForward  13389 192.168.10.12:3389

パスワードなしでログインできるようにしておく

sudo su - tunnel
ssh-keygen
ssh-copy-id vamdemic.vps

systemdユニットファイルを次のように書き換える(ユーザーを変更)

[Unit]
Description=autossh: %I
Documentation=file:///usr/share/doc/autossh/README.service man:autossh(1)
After=network.target

[Service]
User=tunnel
Environment="AUTOSSH_GATETIME=0"
EnvironmentFile=/etc/autossh/%i.conf
ExecStart=/usr/bin/autossh $OPTIONS

[Install]
WantedBy=multi-user.target

/etc/autosshの下に接続先を指定するファイルを作成

# cat /etc/autossh/web.conf
OPTIONS=vamdemic.vps -M 0 -C -N

サービス起動

systemctl start autossh@web
systemctl enable autossh@web
systemctl status autossh@web

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)