SSH
セキュアシェルプロトコル(SSH)は、ユーザーがコマンドラインを通じてデバイスにリモートアクセスすることを可能にします。Cloudflare Zero Trustを使用すると、サーバーの受信ポートを開くリスクなしに、SSHサーバーをインターネット上で利用可能にすることができます。
Cloudflare Zero Trustは、SSHサーバーへの安全なアクセスを提供するための2つのソリューションを提供しています:
この例では、Google Cloud Platform(GCP)の仮想マシン(VM)上にSSHサーバーをセットアップする方法を説明しますが、SSH接続をサポートする任意のマシンを使用できます。
VMインスタンスを作成する前に、SSHキーのペアを作成する必要があります。
-
ターミナルを開き、次のコマンドを入力します:
Terminal window ssh-keygen -t rsa -f ~/.ssh/gcp_ssh -C <username in GCP> -
プロンプトが表示されたらパスフレーズを入力します。2回入力する必要があります。
2つのファイルが生成されます:
gcp_ssh(プライベートキーを含む)とgcp_ssh.pub(パブリックキーを含む)。 -
コマンドラインで次のように入力します:
Terminal window cat ~/.ssh/gcp_ssh.pub -
出力をコピーします。これはGCPでVMインスタンスを作成する際に使用されます。
SSHキーのペアが作成されたので、VMインスタンスを作成できます。
- Google Cloud Console ↗にアクセスし、新しいプロジェクトを作成 ↗します。
- Compute Engine > VMインスタンスに移動します。
- インスタンスを作成を選択します。
- VMインスタンスに名前を付けます(例:
ssh-server)。 - 詳細オプション > セキュリティ > アクセス管理にスクロールします。
- 手動で生成されたSSHキーを追加の下で、アイテムを追加を選択し、作成したパブリックキーを貼り付けます。
- 作成を選択します。
- VMインスタンスが稼働したら、SSHの隣のドロップダウンを開き、_ブラウザウィンドウで開く_を選択します。
You can use Cloudflare Tunnel to create a secure, outbound-only connection from your server to Cloudflare’s edge. This requires running the cloudflared daemon on the server. Users reach the service by installing the Cloudflare WARP client on their device and enrolling in your Zero Trust organization. Remote devices will be able to connect as if they were on your private network. By default, all devices enrolled in your organization can access the service unless you build policies to allow or block specific users.
-
Create a Cloudflare Tunnel for your server by following our dashboard setup guide. You can skip the connect an application step and go straight to connecting a network.
-
In the Private Networks tab for the tunnel, enter the private IP address of your server (or a range that includes the server IP). In GCP, the server IP is the Internal IP of the VM instance.
-
(Optional) Set up Zero Trust policies to fine-tune access to your server.
To connect your devices to Cloudflare:
- Deploy the WARP client on your devices in Gateway with WARP mode. The Cloudflare certificate is only required if you want to display a custom block page or filter HTTPS traffic.
- Create device enrollment rules to determine which devices can enroll to your Zero Trust organization.
By default, WARP excludes traffic bound for RFC 1918 space ↗, which are IP addresses typically used in private networks and not reachable from the Internet. In order for WARP to send traffic to your private network, you must configure Split Tunnels so that the IP/CIDR of your private network routes through WARP.
-
First, check whether your Split Tunnels mode is set to Exclude or Include mode.
-
If you are using Include mode, add your network’s IP/CIDR range to the list. Your list should also include the domains necessary for Cloudflare Zero Trust functionality.
-
If you are using Exclude mode:
- Delete your network’s IP/CIDR range from the list. For example, if your network uses the default AWS range of
172.31.0.0/16, delete172.16.0.0/12. - Re-add IP/CDIR ranges that are not explicitly used by your private network. For the AWS example above, you would add new entries for
172.16.0.0/13,172.24.0.0/14,172.28.0.0/15, and172.30.0.0/16. This ensures that only traffic to172.31.0.0/16routes through WARP.
- Delete your network’s IP/CIDR range from the list. For example, if your network uses the default AWS range of
By tightening the private IP range included in WARP, you reduce the risk of breaking a user’s access to local resources.
アプリケーションとユーザーデバイスをセットアップしたら、ユーザーはプライベートIPアドレスを使用してマシンにSSH接続できます。SSHサーバーがSSHキーを必要とする場合、コマンドにキーを含める必要があります。
ssh -i ~/.ssh/gcp_ssh <username>@<server IP>Cloudflare Tunnel can also route applications through a public hostname, which allows users to connect to the application without the WARP client. This method requires having cloudflared installed on both the server machine and on the client machine, as well as an active zone on Cloudflare. The traffic is proxied over this connection, and the user logs in to the server with their Cloudflare Access credentials.
The public hostname method can be implemented in conjunction with routing over WARP so that there are multiple ways to connect to the server. You can reuse the same tunnel for both the private network and public hostname routes.
-
ダッシュボード設定ガイドに従ってCloudflareトンネルを作成します。
-
パブリックホスト名タブで、ドロップダウンメニューからドメインを選択し、任意のサブドメインを指定します(例:
ssh.example.com)。 -
サービスで_ SSH_を選択し、
localhost:22を入力します。SSHサーバーがトンネルをインストールしたマシンとは異なる場合は、<server IP>:22を入力します。 -
ホスト名を保存を選択します。
-
(推奨)自己ホストアプリケーションをCloudflare Accessに追加して、サーバーへのアクセスを管理します。
ユーザーは、cloudflaredを通じて認証するか、ブラウザレンダリングされたターミナルからデバイスに接続できます。
-
クライアントマシンに
cloudflaredをインストールします。 -
SSH構成ファイルに一度だけ変更を加えます:
Terminal window vim ~/.ssh/config -
次の値を入力し、
ssh.example.comを作成したホスト名に置き換えます。Host ssh.example.comProxyCommand /usr/local/bin/cloudflared access ssh --hostname %hcloudflaredのパスは、OSやパッケージマネージャによって異なる場合があります。たとえば、HomebrewでmacOSにcloudflaredをインストールした場合、パスは/opt/homebrew/bin/cloudflaredです。 -
サービスに到達するためのコマンドを実行して接続をテストできます:
Terminal window ssh <username>@ssh.example.comコマンドが実行されると、
cloudflaredはブラウザウィンドウを起動し、接続を確立する前にアイデンティティプロバイダーで認証するように促します。
エンドユーザーは、Cloudflareのブラウザベースのターミナルを使用して、設定なしでSSHサーバーに接続できます。ユーザーがパブリックホスト名のURL(例:https://ssh.example.com)にアクセスし、Accessの資格情報でログインすると、Cloudflareはブラウザにターミナルをレンダリングします。
有効にするには、ブラウザレンダリングを有効にするを参照してください。