Setting up local authentication

You must set up authentication in your environment before you can access any hosted repositories from your system. This includes performing standard Git operations like git clone, git pull, and git push. After you have set up authentication, you can access any hosted repository for which you have the appropriate roles and permissions.

A local authentication setup is not required to perform operations in the source console (for example, to browse the contents of a repository).

Cloud Source Repositories supports the following types of authentication:

SSH

Cloud Source Repositories allows you to use SSH public key authentication to access hosted repositories. In this scenario, you first generate a key pair on the local system from which you want to access the repository. Then you register the public key with Google Cloud. If you already have an SSH key pair on your system, you can re-use those keys for authentication. You can register up to 20 public keys per Google Account.

Cloud Source Repositories supports the following SSH key types:

  • RSA (for keys with more than 2048 bits only)
  • ECDSA
  • ED25519

Generating a key pair

The SSH key pair consists of a private key that resides on your local system and a public key that you register with Google Cloud.

Generating a key pair on Linux or macOS

  1. Make sure that OpenSSH is installed on your local system.

  2. Enter the following at a command prompt:

    ssh-keygen -t KEY_TYPE -C "USER_EMAIL"
    

    where USER_EMAIL is your e-mail address and KEY_TYPE is one of the following:

    • rsa
    • ecdsa
    • ed25519

    For example:

    ssh-keygen -t rsa -C "user@example.com"
    

    When you run ssh-keygen, it prompts you for a passphrase and the name of a file where the public key will be stored.

Generating a key pair on Windows

  1. Make sure that PuTTY is installed on your local system.

  2. Start PuTTYGen from the Windows Start Menu.

  3. In the window that opens, select the key type from the Parameters field.

  4. Click Generate.

    PuTTYGen displays the generated public key string.

  5. Specify a passphrase to protect the key pair.

  6. Click Save Public Key and Save Private Key to save the key pair you generated to your local system.

Finding existing keys

You can also use an existing key pair for SSH authentication.

Finding existing keys on Linux or macOS

By default, public key files are located in your ~/.ssh directory.

Enter the following at a command prompt:

ls -a ~/.ssh

The default filenames are:

  • id_rsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub

Finding existing keys on Windows

  1. Start PuTTYGen from the Windows Start Menu.

  2. In the Window that opens, click Load.

  3. Browse the local filesystem for your public key file and select the file.

    PuTTYGen displays the public key string. If you specified a passphrase when you saved the key file, PuTTYGen prompts you to enter it before you can view the public key.

Registering a public key

  1. Open the Manage SSH Keys page in the source console:

    Open Cloud Source Repositories

  2. Click Register SSH Key.

  3. Enter a unique name for the key in the Key Name field when prompted.

  4. Copy the key string from your public key file into the Key field.

  5. Click Register.

After you set up SSH authentication, you can clone any repository for which you have the required roles and permissions, or push the contents of a local repository to a new empty hosted repository.

Cloud SDK

Cloud Source Repositories also allows you to use Cloud SDK authentication to access hosted repositories. In this scenario, you run the gcloud init command on your system to set up local authentication. To clone a hosted repository to your local filesystem, you run gcloud source repos clone, which creates a new local directory, fetches the repository contents, and performs other initialization tasks.

  1. Make sure that the Cloud SDK is installed on your local system.

  2. On your local system, run gcloud init:

    gcloud init
    
  3. Run gcloud source repos clone to clone the repository:

    gcloud source repos clone REPOSITORY_NAME --project=PROJECT_ID
    

    where REPOSITORY_NAME is repository name and PROJECT_ID is the ID of the GCP project where the repository is located.

    For example:

    gcloud source repos clone test-repo --project=example-project
    

After you set up Cloud SDK authentication, you can interact with the hosted repository on Cloud Source Repositories using the standard Git commands.

Manually generated credentials

You can also use manually generated credentials for authentication. Cloud Source Repositories provides a set of scripts you can use to manually generate the credentials you need to access hosted repositories.

  1. Generate and store your Git credentials.

  2. Open a terminal window.

  3. Type the following command:

    git clone https://source.developers.google.com/p/PROJECT_ID/r/REPOSITORY_NAME
    

    Where:

    • PROJECT_ID is the name of your project
    • REPOSITORY_NAME is the name of your repository

After you set up authentication with manually generated credentials, you can interact with the hosted repository on Cloud Source Repositories using the standard Git commands.

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
Cloud Source Repositories