使用 ssh-keygen 生成密钥对:
ssh-keygen
将公钥写入服务器对应用户的 $env:USERPROFILE\.ssh\authorized_keys:
$authorizedKey = Get-Content -Path $env:USERPROFILE\.ssh\id_ed25519.pub $remotePowershell = "powershell New-Item -Force -ItemType Directory -Path $env:USERPROFILE\.ssh; Add-Content -Force -Path $env:USERPROFILE\.ssh\authorized_keys -Value '$authorizedKey'" ssh <your user name>@<server> $remotePowershell
注释服务器 C:\ProgramData\ssh\sshd_config 的最后两行,阻止 sshd 修改具有管理员权限的用户使用的 authorized_keys。