A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/compute/docs/tutorials/service-account-ssh below:

Configure apps to use SSH | Compute Engine Documentation

Skip to main content Configure apps to use SSH

Stay organized with collections Save and categorize content based on your preferences.

This document describes how to configure apps to programmatically connect between two virtual machine (VM) instances using SSH and OS Login. Enabling apps to use SSH can be useful for automating system management processes.

All code samples used in this guide is hosted on the GoogleCloudPlatform/python-docs-samples GitHub page.

Before you begin Set up an SSH app

Set up your app to manage SSH keys and initiate SSH connections to Compute Engine VMs. At a high level, your app should do the following:

  1. Import the Google OS Login library to build client libraries, which enables you to authenticate with the OS Login API.
  2. Initialize the OS Login Client object to enable your app to use OS Login.
  3. Implement a create_ssh_key() method that generates an SSH key for the VM's service account and adds the public key to the service account.
  4. Call the get_login_profile() method from the OS Login library to get the POSIX user name that the service account uses.
  5. Implement a run_ssh() method to execute a remote SSH command.
  6. Remove the temporary SSH key files.
Sample SSH app

The oslogin_service_account_ssh.py sample app demonstrates a possible implementation of an SSH app. In this example, the app uses the run_ssh() method to execute a command on a remote instance and return the command output.

Run the SSH app

After you create an app that uses SSH, you can run the app by following a process similar to the following example, which installs and runs the oslogin_service_account_ssh.py sample app. The libraries you install may differ, depending on the programming language the app uses.

Alternatively, you can write an app that imports oslogin_service_account_ssh.py and runs it directly.

  1. Connect to the VM that hosts the SSH app.

  2. On the VM, install pip and the Python 3 client library:

    sudo apt update && sudo apt install python3-pip -y && pip install --upgrade google-cloud-os-login requests
    
  3. Optional: If you are using the oslogin_service_account_ssh.py sample app, download it from GoogleCloudPlatform/python-docs-samples:

    curl -O https://raw.githubusercontent.com/GoogleCloudPlatform/python-docs-samples/master/compute/oslogin/oslogin_service_account_ssh.py
    
  4. Run the SSH app. The sample app uses argparse to accept variables from the command line. In this example, instruct the app to install and run cowsay on another VM in your project.

    python3 service_account_ssh.py \
       --cmd 'sudo apt install cowsay -y && cowsay "It works!"' \
       --project=PROJECT_ID --instance=VM_NAME --zone=ZONE
    

    Replace the following:

    The output is similar to the following:

    ⋮
    ___________
     It works!
    -----------
          \   ^__^
           \  (oo)\_______
              (__)\       )\/\
                  ||----w |
                  ||     ||
    
What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This guide outlines the process of configuring applications to establish programmatic connections between two virtual machine (VM) instances using SSH and OS Login, which can enhance system management automation."],["The document details the steps to set up an SSH app, including importing the Google OS Login library, initializing the OS Login Client, generating SSH keys, obtaining the service account's POSIX username, implementing an SSH command execution method, and managing temporary SSH key files."],["A sample Python app, `oslogin_service_account_ssh.py`, is provided as an example, demonstrating how to use the OS Login API to apply public SSH keys for a service account and execute commands on a remote instance over SSH, with code hosted on GitHub."],["Instructions are given on how to prepare your environment and run the provided sample app, including connecting to the VM, installing necessary libraries, and executing a remote command via SSH, including examples."],["The guide references how to view the full code sample on Github, and to learn more about SSH connections in Compute Engine, including SSH key configuration and storage."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4