Blog Home
Updated: 2023 Oct 09

如何生成密钥连接Linux实例

SRC:https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys

Creating a new SSH key

If you do not have an existing private SSH key file and a matching public SSH key file that you can use, generate a new SSH key. If you want to use an existing SSH key, locate the public SSH key file.

  1. Open a terminal on your workstation and use the ssh-keygen command to generate a new key. Specify the -C flag to add a comment with your username.
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
  1. Restrict access to your private key so that only you can read it and nobody can write to it.
chmod 400 ~/.ssh/[KEY_FILENAME]

Locating an SSH key

If you created a key on a Linux or macOS workstation by using the ssh-keygen tool, your key was saved to the following locations:

+ Public key file: ~/.ssh/[KEY_FILENAME].pub
+ Private key file: ~/.ssh/[KEY_FILENAME]

Connect to instance

ssh -i ~/.ssh/[KEY_FILENAME] [HOSTNAME/HOSTIP]

Comments:

Email questions, comments, and corrections to hi@smartisan.dev.

Submissions may appear publicly on this website, unless requested otherwise in your email.