1. AWSサーバー上にt3.nanoのインスタンスを作る
作るだけです。
2. 家のマシンの設定
まずはautosshのインストール。
sudo apt install autossh
AWSサーバー上のインスタンスに設定する鍵を生成。
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_home
/etc/systemd/system/autossh.serviceを作成
[Unit]
Description=AutoSSH Service
After=network.target
[Service]
User=saru
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -i /home/saru/.ssh/id_rsa_home -M 40001 -N -R 10022:localhost:22 ubuntu@X.X.X.X > /dev/null 2>&1
Restart=always
RestartSec=5s
StartLimitIntervalSec=60
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
3. AWSサーバー上での作業
家のサーバーで作ったid_rsa_home.pubを.ssh/authorized_keysに追加
4. 家のサーバー上で動作確認
/usr/bin/autossh -i /home/saru/.ssh/id_rsa_home -M 40001 -R 10022:localhost:22 ubuntu@X.X.X.X
接続出来たらautossh.serviceを有効化
sudo systemctl enable autossh
autossh.をスタート
sudo systemctl start autossh
再起動
reboot
5. AWS上のサーバーで動作確認
ssh -i .ssh/id_rsa_home_bridge -p 10022 saru@localhost