[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Forward SSH tunnel\n\nThe following steps describe how to set up connectivity to a source database using a forward SSH tunnel.\n\nStep 1: Choose a host on which to terminate the tunnel\n------------------------------------------------------\n\nThe first step to set up SSH tunnel access for your database is to choose the host that will be used to terminate the tunnel. The tunnel can be terminated on either the database host itself, or on a separate host (the tunnel server).\n\n### Use the database server\n\nTerminating the tunnel on the database has the advantage of simplicity. There's one fewer host involved, so there are no additional machines and their associated costs. The disadvantage is that your database server might be on a protected network that doesn't have direct access from the internet.\n\n### Use a tunnel server\n\nTerminating the tunnel on a separate server has the advantage of keeping your database server inaccessible from the internet. If the tunnel server is compromised, then it's one step removed from the database server. We recommend that you remove all non-essential software and users from the tunnel server and closely monitor it with tools, such as an intrusion detection system (IDS).\n\nThe tunnel server can be any Unix or Linux host that:\n\n1. Can be accessed from the internet using SSH.\n2. Can access the database.\n\n | **Note:** For managed services, the tunnel server must be external to the source database. If your source database is self-hosted, you can set up the tunnel server on the same server or virtual machine (VM) that runs the source database.\n\nStep 2: Create an IP allowlist\n------------------------------\n\nThe second step to set up SSH tunnel access for your database is to allow network traffic to reach the tunnel server or the database host using SSH, which is generally on TCP port 22.\n\nAllow network traffic from each of the [IP addresses for the\nregion](/datastream/docs/ip-allowlists-and-regions) where Datastream\nresources are created.\n\nStep 3: Use the SSH tunnel\n--------------------------\n\nProvide the tunnel details in the connection profile configuration. For more\ninformation, see [Create a connection\nprofile](/datastream/docs/create-connection-profiles).\n\nTo authenticate the SSH tunnel session, Datastream requires either the password for the tunnel account, or a unique private key. To use a unique private key, you can use OpenSSH or OpenSSL command-line tools to generate keys.\n\nDatastream stores the private key securely as part of the Datastream connection profile configuration. You must add the public key manually to the bastion host's `~/.ssh/authorized_keys` file.\n\n### Generate private and public keys\n\nYou can generate SSH keys using the following method:\n\n- `ssh-keygen`: An OpenSSH command-line tool to generate SSH key pairs.\n\n Useful flags:\n - `-t`: Specifies the type of key to create, for example:\n\n `ssh-keygen -t rsa`\n\n `ssh-keygen -t ed25519`\n - `-b`: Specifies the key length in the key to create, for example:\n\n `ssh-keygen -t rsa -b 2048`\n - `-y`: Reads a private OpenSSH format file and prints an OpenSSH public key to standard output.\n\n - `-f`: Specifies the filename of the key file, for example:\n\n `ssh-keygen -y [-f `\u003cvar translate=\"no\"\u003eKEY_FILENAME\u003c/var\u003e`]`\n\n For more information about supported flags, see [OpenBSD documentation](https://man.openbsd.org/ssh-keygen).\n\nYou can generate a private PEM key using the following method:\n\n- `openssl genpkey`: An OpenSSL command-line tool to generate a PEM private key.\n\n Useful flags:\n - `algorithm`: Specifies the public key algorithm to use, for example:\n\n `openssl genpkey -algorithm RSA`\n - `-out`: Specifies the filename to which to output the key, for example:\n\n `openssl genpkey -algorithm RSA -out `\u003cvar translate=\"no\"\u003ePRIVATE_KEY_FILENAME\u003c/var\u003e`.pem`\n | To use the key generated by this command, you need to generate a public OpenSSH key for it using the following command:\n |\n | `ssh-keygen -y -f `\u003cvar translate=\"no\"\u003ePRIVATE_KEY_FILENAME\u003c/var\u003e`.pem \u003e\n | `\u003cvar translate=\"no\"\u003ePUBLIC_KEY_FILENAME\u003c/var\u003e`.pub`.\n | You can then add the \u003cvar translate=\"no\"\u003ePUBLIC_KEY_FILENAME\u003c/var\u003e`.pub` key to the `~/.ssh/authorized_keys` file.\n\n \u003cbr /\u003e\n\n For more information about supported flags, see [OpenSSL documentation](https://www.openssl.org/docs/man1.1.1/man1/openssl-genpkey.html).\n\nWhat's next\n-----------\n\n- Learn how about other network [connectivity methods](/datastream/docs/network-connectivity-options)."]]