Windows SSH 远程连接 Linux
# 创建密钥
# 创建
linux 服务器端的终端中执行命令 ssh-keygen
,之后一直按Enter即可,这样会在将在 ~/.ssh/
路径下生成公钥(id_rsa.pub)和私钥(id_rsa)
注意:也可以在 windows 端生成密钥,只需要保证公钥在服务器端,私钥在本地端即可。
# 安装
在服务器端~/.ssh/
路径下执行以下命令,在服务器上安装公钥
cat id_rsa.pub >> authorized_keys
chmod 600 *
修改文件权限,只允许文件拥有者读写
# 配置密钥
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
1
2
3
4
5
2
3
4
5
# 连接主机
打开命令行,输入 ssh 远程机器别名
即可免密连接到主机
# 自动连接主机
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"
}
]
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
VS Code 远程开发或是命令行 SCP 文件传输请看推荐阅读
# 参考文章
Windows Terminal 通过密钥远程连接Linux服务器 - 知乎 (zhihu.com) (opens new window)
# 推荐阅读
使用SSH命令行传输文件到远程服务器 - Magic.C - 博客园 (cnblogs.com) (opens new window)
编辑 (opens new window)
上次更新: 2023/10/14, 10:01:13