【全面解析】Windows 如何使用 SSH 密钥远程连接 Linux 服务器

简介: 【全面解析】Windows 如何使用 SSH 密钥远程连接 Linux 服务器

创建密钥

创建

linux 服务器端的终端中执行命令 ssh-keygen,之后一直按Enter即可,这样会在将在 ~/.ssh/ 路径下生成公钥(id_rsa.pub)和私钥(id_rsa)

注意:也可以在 windows 端生成密钥,只需要保证公钥在服务器端,私钥在本地端即可。

安装

在服务器端~/.ssh/路径下执行以下命令,在服务器上安装公钥
cat id_rsa.pub >> authorized_keys

chmod 600 * 修改文件权限,只允许文件拥有者读写

image-20230720223300189

配置密钥

windows 端 编辑 ~/.ssh/config 文件(没有则创建)

Host 远程主机别名,HostName 远程主机IP或域名,Port ssh端口,User 登录用户,IdentityFile 密钥文件位置

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

连接主机

打开命令行,输入 ssh 远程机器别名 即可免密连接到主机

image-20230720222923838

自动连接主机

Windows Terminal 设置 json 配置文件,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

VS Code 远程开发或是命令行 SCP 文件传输请看推荐阅读

参考文章

Windows Terminal 通过密钥远程连接Linux服务器 - 知乎 (zhihu.com)

推荐阅读

使用SSH命令行传输文件到远程服务器 - Magic.C - 博客园 (cnblogs.com)

VS Code Remote SSH配置 - 知乎 (zhihu.com)

目录
相关文章
|
6月前
|
安全 Linux 生物认证
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
247 0
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
|
6月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
594 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
6月前
|
安全 Linux 生物认证
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
313 17
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
|
6月前
|
Linux API iOS开发
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
449 14
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
6月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
309 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
6月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
559 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
7月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
448 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
7月前
|
JSON 安全 Linux
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
252 1
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
|
7月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
507 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
|
7月前
|
安全 Ubuntu Linux
Nexpose 8.21.0 for Linux & Windows - 漏洞扫描
Nexpose 8.21.0 for Linux & Windows - 漏洞扫描
208 4
Nexpose 8.21.0 for Linux & Windows - 漏洞扫描

热门文章

最新文章