[Comprehensive analysis] How Windows uses SSH keys to remotely connect to Linux servers

create key

create

Execute the command in the terminal of the linux server , and then press Enter all the time, so that the public key (id_rsa.pub) and private key (id_rsa) ssh-keygenwill be generated under the path~/.ssh/

Note: The key can also be generated on the windows side, just ensure that the public key is on the server side and the private key is on the local side.

Install

Execute the following command under the server ~/.ssh/path to install the public key on the server
cat id_rsa.pub >> authorized_keys

chmod 600 *Modify file permissions to allow only the file owner to read and write

image-20230720223300189

configuration key

Edit ~/.ssh/configthe file on windows side (create if there is none)

Host remote host alias, HostName remote host IP or domain name, Port ssh port, User login user, IdentityFile key file location

Host centos7
    HostName 81.*.*.*
    Port 22
    User root
    IdentityFile ~/.ssh/id_rsa_centos7

connect host

Open the command line and enter ssh 远程机器别名to connect to the host without password

image-20230720222923838

Automatically connect to the host

Windows Terminal sets the json configuration file, adding the last item in the list

"profiles": 
{
    
    
    "list": 
    [
        {
    
    
            "guid": "{16208362-94fc-5b1f-a491-5b2624d5ab56}",
            "hidden": true,
            "name": "Visual Studio Debug Console",
            "source": "VSDebugConsole"
        },
        {
    
    
            "closeOnExit": "graceful",
            "commandline": "ssh centos7",
            "guid": "{fb35f95b-3a1a-5414-8efa-4ccb3a4dd25e}",
            "name": "CentOS7"
        }
    ]
},

image-20230720223124103

For VS Code remote development or command-line SCP file transfer , please see recommended reading

reference article

Windows Terminal remotely connects to a Linux server through a key - Zhihu (zhihu.com)

recommended reading

Use the SSH command line to transfer files to a remote server - Magic.C - Blog Garden (cnblogs.com)

VS Code Remote SSH configuration - Zhihu (zhihu.com)

This article is published by OpenWrite, a multi-post platform for blogging !

Guess you like

Origin blog.csdn.net/m0_63748493/article/details/131841561