1. 生成密钥对
在客户端生成密钥对
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
2. 将公钥传到服务器
cat ~/.ssh/id_rsa.pub | ssh username@wsl2_ip "cat >> ~/.ssh/authorized_keys"
3. 其他服务器设置
sudo nano /etc/ssh/sshd_config
# 允许远程连接
PermitRootLogin yes
# 启用无密码登录
PasswordAuthentication no
PubkeyAuthentication yes