20240211185359 Cloudflareでsshアクセスできるようにする

raspicloudflaresshserver

注意

Raspi4 Cloudflareでトンネルを作る と同じ。設定方法がどんどん変わる上、私はその専門ではない

前提

手順

サーバー(raspi)側

CNAME recordの追加

cloudflare@saipi5$ cloudflared tunnel route dns **** pi4.kinoshita-lab.org(ここは好きな名前にする)

2024-02-12T11:33:59Z INF Added CNAME pi4.kinoshita-lab.org which will route to this tunnel tunnelID=****

**** は cloudflare トンネルのtoken(private) を入れる。

systemで動いているcloudflaredにsshの設定を変更。 httpとsshをhostnameで分けるようにする。

tunnel: ****
credentials-file: /var/lib/cloudflare/.cloudflared/****.json

ingress:
    - hostname: notes.kinoshita-lab.org
      service: http:localhost
    - hostname: pi4.kinoshita-lab.org
      service: ssh://localhost:??(sshのポート名)
    - service: http_status:404

クライアント(wsl2のubuntuなど)側

.ssh/config に、 cloudflaredを使う設定にしたssh設定を追記。

Host pi4.kinoshita-lab.org (cloudflareで作ったsshのtunnelのドメイン)
        Port xxxxx (自分が設定したポート番号)
        ProxyCommand cloudflared access ssh --hostname %h
$ ssh pi4.kinoshita-lab.org

でログインできればOK。

cf.