Tailscaleで自宅の外からVSCodeに繋ぐ
先月にPCを自作したけれど、もちろんラップトップではなくデスクトップなので持ち運びができない。せっかくお金をかけて作ったPCなので、自宅の外だろうがハイスペPCを使いたい。
Tailscale
自宅PCに繋げるために話題のTailscaleを選んだ。VPNはいまいち詳しくないので同僚から評判という理由だけで選んだ。
Tailscaleとは、
Tailscale is a VPN service that makes the devices and applications you own accessible anywhere in the world, securely and effortlessly. It enables encrypted point-to-point connections using the open source WireGuard protocol, which means only devices on your private network can communicate with each other.
というものである。詳細は下記。
What is Tailscale? · Tailscale
個人利用であれば無料で使える点も良い。
インストール
Tailscaleを使うためには接続先と接続元のそれぞれにtailscaleをインストールする必要がある。
yay -S tailscale # Manjaro
brew install tailscale # Mac
セットアップ
tailscaleを起動するとブラウザ上でセットアップツアーが行われるのでそれに従えば良い。tailscaleを起動してpingの確認まで行うので完遂すれば接続できている。
セットアップ時にはIPアドレスを使ってpingをするが、もちろんHost名でも接続ができる。tailscale status
を実行するとターミナル上からも確認できる。tailscale ping $host_name
とすればpingもできるしコマンド変えればsshもできる。
VSCodeの設定
まずcode-serverの設定を行う。設定方法は下記に記載されている。iPadって書いてあるけど別に関係ないのでそのまま設定すればよし。
Coding on iPad using VSCode, Caddy, and code-server · Tailscale
tailscaleのインストールはされているのでcode-serverのインストールから行う。code-serverもyayで取得できるのでyay -S code-server
でOK。
設定ファイルが~/.config/code-server/config.yaml
に置かれるので、そこをリンク先の通りに変更してあげる。
接続元の端末のブラウザから$サーバーIP:$config.yamlで設定したport番号
に接続するとVSCodeが起動する。