VSCode uses ssh to connect to remote servers without secret

To remotely connect to the host through SSH in VSCode and realize password-free login, you can follow the steps below:

  1. First, make sure you have established an SSH connection between your local machine and the remote host. You can connect to a remote host on your local terminal with the following command:

    ssh username@hostname
    

    This will ask you to enter your password for authentication. If you can successfully connect to the remote host, then the SSH connection has been established.

  2. Next, you need to generate an SSH key pair on your local machine. Skip this step if you already have a key pair. Otherwise, run the following command on a local terminal to generate a key pair:

    ssh-keygen -t rsa

    This will generate an RSA key pair, including public and private keys. When prompted for a filename, you can choose to accept the default, or specify a custom filename.

  3. Then, copy the public key to authorized_keysa file on the remote host. You can copy the public key to the remote host with the following command:

    ssh-copy-id username@hostname

    This will automatically add your public key to ~/.ssh/authorized_keysa file on the remote host, and will ask you to enter the remote host's passphrase to authenticate.

    If ssh-copy-idthe command is not available on your system, you can manually add the contents of the public key to authorized_keysa file on the remote host.

  4. Now, you can open the remote folder in VSCode and connect to the remote host. In VSCode's sidebar, click the Remote Connection button in the lower left corner and select the "Remote-SSH: Connect to Host" option.

  5. In the input box that pops up, enter the user name and host name (or IP address) of the remote host, and then select the private key file you generated in step 2. Click the "Connect" button.

    If everything is set up correctly, VSCode will attempt to authenticate using the private key and connect to the remote host.

 

Guess you like

Origin blog.csdn.net/u013250861/article/details/131294247