Logging into Linux Instance via SSH Key

Last updated: 2020-08-27 15:42:54

    Overview

    This document describes how to use a SSH key to log in to a Linux instance from a local Linux, Mac OS or Windows.

    Supported Systems

    Linux, Mac OS or Windows (including Windows 10 and Windows Server 2019)

    Authentication Method

    Password or Key

    Prerequisites

    • You must already have the admin account and password (or key) to log in to the instance.
    • A public IP has been purchased for your CVM instance, and port 22 is open (this is open by default for a CVM purchased with quick configuration).

    Directions

    Using the password

    1. Execute the following command to connect to the Linux CVM.

      Note:

      If your local computer uses Mac OS, you must open the terminal provided by the system and then execute the following command.
      If your local computer uses Linux, you can directly execute the following command.
      If your local computer uses Windows 10 or Windows Server 2019, you must first open the command prompt CMD and then execute the following command.

      ssh <username>@<hostname or IP address>
      • username refers to the default account name obtained as a prerequisite.
      • hostname or IP address refers to the public IP address or custom domain name of your Linux instance.
    2. Enter the password you have already obtained, and press Enter to log in.

    Using a key

    1. Execute the following command to set the private key file readable only to you.

      • If your local computer uses Mac OS, you must first open the terminal provided by the system and then execute the following command.
      • If your local computer uses Linux, you can directly execute the following command.
        chmod 400 <The absolute path of the private key downloaded to be associated with the CVM>
      • If your local computer uses Windows 10, you must first open the command prompt CMD and then execute the following commands.
        icacls <The absolute path of the private key downloaded to be associated with the CVM> /grant <Username>:F
        icacls <The absolute path of the private key downloaded to be associated with the CVM> /inheritancelevel:r
    2. Execute the following command for remote login.

      ssh -i <The absolute path of the private key downloaded to be associated with the CVM> <username>@<hostname or IP address>
      • username refers to the default account name obtained as a prerequisite.
      • hostname or IP address refers to the public IP address or custom domain name of your Linux instance.

      For example, execute the ssh -i "Mac/Downloads/shawn_qcloud_stable" ubuntu@192.168.11.123 command to remotely log in to the Linux CVM.

    Subsequent Operations

    After logging in to the CVM, you can build a personal website or forum or perform other operations. For more information, please see:

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help