这里写自定义目录标题
前提条件:
- 已经安装了 Git for Windows,这会自动安装 SSH 客户端和服务器组件
- 远程 Linux 服务器已安装并配置了SSH服务。
- 您有足够的权限在远程服务器上进行操作。
1. 生成 SSH 密钥对
- 找到C:\Users\你的用户名\下的.ssh文件夹,右键通过Git Bash打开。
- 运行以下命令来生成 SSH 密钥对
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
按提示操作,可以选择保存密钥的位置(默认为C:\Users\你的用户名\下的.ssh\id_rsa),连续点三次回车,不要输入密码。
2. 将公钥发送到远程服务器
- 在 Git Bash 中运行以下命令将公钥发送到远程服务器
ssh-copy-id -i id_rsa.pub root@192.168.1.100
alientek@192.168.1.100
用户名:alientek, ip:你的服务器ip地址
3. 测试 SSH 连接
- 在 Git Bash 中运行以下命令测试 SSH 连接:
ssh root@47.101.59.20
4. 使用 VSCode 连接到远程服务器
# 配置文件
Host alientek
HostName 192.168.1.100
User alientek
IdentityFile C:\Users\你的用户名\.ssh/id_rsa
其中 alias 是您定义的主机别名,HostName 是远程服务器的 IP 地址或域名,User 是要登录的用户名,IdentityFile 是您的私钥路径。