gcloud compute config-ssh Stay organized with collections Save and categorize content based on your preferences.
- NAME
- gcloud compute config-ssh - populate SSH config files with Host entries from each instance
- SYNOPSIS
gcloud compute config-ssh[--dry-run][--force-key-file-overwrite][--remove][--ssh-config-file=SSH_CONFIG_FILE][--ssh-key-file=SSH_KEY_FILE][GCLOUD_WIDE_FLAG …]
- DESCRIPTION
gcloud compute config-sshmakes SSHing to virtual machine instanceseasier by adding an alias for each instance to the user SSH configuration(~/.ssh/config) file.In most cases, it is sufficient to run:
gcloudcomputeconfig-sshEach instance will be given an alias of the form
NAME.ZONE.PROJECT.For example, ifexample-instanceresides inus-central1-a, you can SSH to it by running:sshexample-instance.us-central1-a.MY-PROJECTOn some platforms, the host alias can be tab-completed, making the long aliasless daunting to type.
The aliases created interface with SSH-based programs like
scp(1),so it is possible to use the aliases elsewhere:scp~/MY-FILEexample-instance.us-central1-a.MY-PROJECT:~Whenever instances are added, removed, or their external IP addresses arechanged, the remove command must be run to clear the existing configuration andthen the command can set executed to set the configuration to the current state.
This command ensures that the user's public SSH key is present in the project'smetadata. If the user does not have a public SSH key, one is generated using
ssh-keygen(1)(if the--quietflag is given, thegenerated key will have an empty passphrase).- EXAMPLES
- To populate SSH config file with Host entries from each running instance, run:
gcloudcomputeconfig-sshTo remove the change to the SSH config file by this command, run:
gcloudcomputeconfig-ssh--remove - FLAGS
--dry-run- If provided, the proposed changes to the SSH config file are printed to standardoutput and no actual changes are made.
--force-key-file-overwrite- If enabled, the gcloud command-line tool will regenerate and overwrite the filesassociated with a broken SSH key without asking for confirmation in bothinteractive and non-interactive environments.
If disabled, the files associated with a broken SSH key will not be regeneratedand will fail in both interactive and non-interactive environments.
--remove- If provided, any changes made to the SSH config file by this tool are reverted.
--ssh-config-file=SSH_CONFIG_FILE- Specifies an alternative per-user SSH configuration file. By default, this is
.~/.ssh/config --ssh-key-file=SSH_KEY_FILE- The path to the SSH key file. By default, this is
.~/.ssh/google_compute_engine
- GCLOUD WIDE FLAGS
- These flags are available to all commands:
--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run
$gcloud helpfor details. - NOTES
- These variants are also available:
gcloudalphacomputeconfig-sshgcloudbetacomputeconfig-ssh
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-05-07 UTC.