在 Azure Stack Hub 上为 Linux 创建 SSH 密钥Create an SSH key for Linux on Azure Stack Hub

可以在 Windows 计算机上为 Linux 计算机创建 SSH(安全外壳)密钥。You can create an SSH (secure shell) key for your Linux machine on a Windows machine. 使用本文中步骤生成的公钥对 VM 进行 SSH 身份验证。Use the public key generated by the steps in this article for SSH authentication with VMs. 如果你使用的是 Windows 计算机,请在 Windows 上安装 Ubuntu,以便通过 bash、ssh、git、apt 等实用工具获取终端。If you are using a Windows machine install Ubuntu on Windows to get a terminal with utilities such as bash, ssh, git, apt, and many more. 运行 ssh-keygen 来创建密钥。Run the ssh-keygen to create your key.

在 Windows 上打开 BashOpen bash on Windows

  1. 如果你没有在计算机上安装适用于 Linux 的 Windows 子系统,请在 Windows 上安装 UbuntuIf you do not have the Windows Subsystem for Linux installed on your machine, install "Ubuntu on Windows.
    有关使用适用于 Linux 的 Windows 子系统的详细信息,请参阅适用于 Linux 的 Windows 子系统的文档For more information about using the Windows Subsystem for Linux, see Windows Subsystem for Linux Documentation.

  2. 在工具栏中键入 Ubuntu,然后选择“打开”。Type Ubuntu in your toolbar and select Open.

使用 ssh-keygen 创建密钥Create a key with ssh-keygen

  1. 在 bash 提示符下键入以下命令:Type the following command from your bash prompt:

    ssh-keygen -t rsa
    

    Bash 将显示以下提示:Bash displays the following prompt:

    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/username/.ssh/id_rsa):
    
  2. 键入文件名和通行短语。Type the filename and passphrase. 再次键入通行短语。Type the passphrase again.

    Bash 将显示以下提示:Bash displays the following:

    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/user/.ssh/id_rsa): key.txt
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in key.txt.
    Your public key has been saved in key.txt.pub.
    The key fingerprint is:
    SHA256:xanotrealoN6z1/KChqeah0CYVeyhL50/0rq37qgy6Ik username@machine
    The key's randomart image is:
    +---[RSA 2048]----+
    |   o.     .      |
    |  . o.   +       |
    | + o .+ o o      |
    |o o .  O +       |
    | . o .o S .      |
    |  o +. .         |
    |.  o +..o. .     |
    |= . ooB +o+ .    |
    |E=..*X=*.. +.    |
    +----[SHA256]-----+
    
  3. 查看公共 ssh 密钥:To view and the public ssh key:

    cat /home/<username>/<filename>
    

    Bash 会显示如下所示的内容:Bash displays something like the following:

    ssh-rsa AAAAB3NzaC1ycTHISISANEXAMPLEDITqEJRNrf6tXy9c0vKnMhiol1BFzHFV3
    +suXk6NDeFcA9uI58VdD/CuvG826R+3OPnXutDdl2MLyH3DGG1fJAHObUWQxmDWluhSGb
    JMHiw2L9Wnf9klG6+qWLuZgjB3TQdus8sZI8YdB4EOIuftpMQ1zkAJRAilY0p4QxHhKbU
    IkvWqBNR+rd5FcQx33apIrB4LMkjd+RpDKOTuSL2qIM2+szhdL5Vp5Y6Z1Ut1EpOrkbg1
    cVw7oW0eP3ROPdyNqnbi9m1UVzB99aoNXaepmYviwJGMzXsTkiMmi8Qq+F8/qy7i4Jxl0
    aignia880qOtQrvNEvyhgZOM5oDhgE3IJ username@machine
    
  4. 复制文本 ssh-rsa [...],一直复制到 username@machinenameCopy the text ssh-rsa [...] up to username@machinename. 请确保文本不包含任何回车符。Make sure the text doesn't include any carriage returns. 使用 AKS 引擎创建 VM 或 Kubernetes 群集时,可以使用此文本。You can use this text when creating your VM or Kubernetes cluster using the AKS engine.

  5. 如果你使用的是 Windows 计算机,可以使用 \\wsl$ 来访问 Linux 文件。If you are on a Windows machine, you can access your Linux files using \\wsl$.

    1. 在工具栏中键入 \\wsl$Type \\wsl$ in your toolbar. 你的发行版的默认窗口随即打开。The default window your distribution open.

    2. 导航到:\\wsl$\Ubuntu\home\<username>,找到公钥和私钥,并将其保存到一个安全位置。Navigate to: \\wsl$\Ubuntu\home\<username> and find the public and private key and save to a secure location.

后续步骤Next steps