[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[],[],null,["# Setting up local authentication\n\nBefore you can access or interact with hosted repositories from your system, you\nmust set up local authentication in your environment.\n\nAfter you set up local authentication, you can access hosted repositories for\nwhich you have the appropriate\n[roles and permissions](/source-repositories/docs/configure-access-control).\nYou can also perform standard Git operations such as `git clone`, `git pull`,\nand `git push`. Local authentication isn't required to perform operations in the\nGoogle Cloud console, for example, to browse the contents of a repository.\n\nCloud Source Repositories supports the following types of authentication:\n\n- [SSH](#ssh)\n- [Google Cloud CLI](#authenticate-using-the-cloud-sdk)\n- [Manually generated credentials](#manually-generated-credentials)\n\nAuthenticate by using SSH\n-------------------------\n\nCloud Source Repositories lets you use SSH public key authentication to\naccess hosted repositories. In this scenario, you first generate a key pair on\nthe local system from which you want to access the repository. Then you register\nthe public key with Google Cloud. If you already have an SSH key pair\non your system, you can re-use those keys for authentication. You can register\nup to 20 public keys per Google Account.\n| **Note:** You cannot configure authentication for service accounts by using SSH keys.\n\nCloud Source Repositories supports three SSH key types:\n\n- RSA (only for keys with more than 2048 bits)\n- ECDSA\n- ED25519\n\n### Generate a key pair\n\nThe SSH key pair consists of a private key that resides on your local system and\na public key that you register with Google Cloud. \n\n### Linux or macOS\n\n1. Ensure that\n [OpenSSH](https://www.openssh.com/)\n is installed on your local system.\n\n2. At a command prompt, enter the following command:\n\n ssh-keygen -t [KEY_TYPE] -C \"[USER_EMAIL]\"\n\n Where:\n - `[USER_EMAIL]` is your email address.\n - `[KEY_TYPE]` is one of the following:\n - `rsa`\n - `ecdsa`\n - `ed25519`\n\n For example: \n\n ssh-keygen -t rsa -C \"user@example.com\"\n\n 1. When prompted, enter a filename for the public key file. To accept the\n default `~/.ssh` location, press **Enter**, otherwise specify a filename.\n\n 2. When prompted, leave the passphrase empty and press **Enter**.\n\n3. [Register your key](#register_a_public_key)\n\n### Windows\n\n1. Ensure that\n [PuTTY](https://www.putty.org/)\n is installed on your local system.\n\n2. From the Windows **Start** menu, start PuTTYGen.\n\n3. In the window that opens, select the key type from the **Parameters**\n field.\n\n4. Click **Generate**.\n\n PuTTYGen displays the generated public key string.\n5. Specify a passphrase to protect the key pair.\n\n6. To save the key pair you generated to your local system, click\n **Save Public Key** and **Save Private Key**.\n\n### Use existing keys\n\nYou can also use an existing key pair for SSH authentication. \n\n### Linux or macOS\n\nBy default, public key files are located in your `~/.ssh` directory.\n\nAt a command prompt, enter the following command: \n\n ls -a ~/.ssh\n\nThe default filenames are:\n\n- `id_rsa.pub`\n- `id_ecdsa.pub`\n- `id_ed25519.pub`\n\n### Windows\n\n1. From the Windows **Start** menu, start PuTTYGen.\n\n2. In the window that opens, click **Load**.\n\n3. Browse the local file system for your public key file and select the\n file.\n\n PuTTYGen displays the public key string. If you specified a passphrase\n when you saved the key file, PuTTYGen prompts you to enter it before you\n can view the public key.\n\n### Register a public key\n\n1. In the Google Cloud console, open the **Manage SSH Keys** page.\n\n [Open Cloud Source Repositories](https://source.cloud.google.com/user/ssh_keys)\n2. Click **Register SSH key**.\n\n The **Register SSH Key** dialog opens.\n3. In the **Key name** field, type a unique name for the key.\n\n4. In the **Key** field, copy the key string from your public key file.\n\n5. Click **Register**.\n\nAfter you set up SSH authentication, you can\n[clone any repository](/source-repositories/docs/cloning-repositories#ssh)\nfor which you have the required roles and permissions, or\n[push the contents](/source-repositories/docs/pushing-code-from-a-repository)\nof a local repository to an empty hosted repository.\n\nAuthenticate by using the gcloud CLI\n------------------------------------\n\nCloud Source Repositories lets you authenticate by using the\ngcloud CLI. In this scenario, you run the\n[`gcloud init`](/sdk/gcloud/reference/init)\ncommand on your system to set up local authentication.\n\n1. Ensure that the\n [gcloud CLI](/sdk/install)\n is installed on your local system.\n\n2. At a command prompt, run `gcloud init`:\n\n gcloud init\n\n3. Follow the instructions.\n\nAfter you set up authentication by using the gcloud CLI, you can use\nstandard Git commands to interact with the hosted repository on\nCloud Source Repositories.\n\nAuthenticate by using manually generated credentials\n----------------------------------------------------\n\nYou can also use manually generated credentials for authentication.\nCloud Source Repositories provides a set of scripts you can use to manually\ngenerate the credentials you need to access hosted repositories.\n\n1. Go to the **Configure Git** page to generate your credentials.\n\n [Go to the Configure Git page](https://source.developers.google.com/auth/start?scopes=https://www.googleapis.com/auth/cloud-platform)\n2. Open a terminal window.\n\n3. Type the following command:\n\n ```\n git clone https://source.developers.google.com/p/PROJECT_ID/r/REPOSITORY_NAME\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is the name of your project\n - \u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e is the name of your repository\n\nAfter you set up authentication with manually generated credentials, you can\ninteract with the hosted repository on Cloud Source Repositories by using the\nstandard Git commands."]]