- 生成密钥对(在本地 Windows 机器)
ssh-keygen -t rsa -b 2048 -C "your_email@example.com"
- 上传公钥到服务器
将id_rsa.pub内容追加到服务器用户的~/.ssh/authorized_keys文件。可以用如下命令(假设你有密码)
type %USERPROFILE%\.ssh\id_rsa.pub | ssh 用户名@服务器IP "cat >> ~/.ssh/authorized_keys"
- 直接连接服务器
ssh 用户名@服务器IP