Window SSH 免密登陆 Linux

背景

一般 我们会用 ssh-copy-id 来复制key,实现免密登陆,但在Window环境下,没有这个命令,也不方便安装 Git for Windows,那如何实现这个功能呢?

替代方案

Windows 11 的 PowerShell 默认支持 ssh,你可以直接运行以下组合命令,效果与 ssh-copy-id 完全相同。
打开 PowerShell,复制并运行以下命令(请将其中的 user@remote_host 替换为你的服务器用户名和 IP):

1
cat ~/.ssh/id_ed25519.pub | ssh user@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"

注:如果你生成的密钥不是 id_ed25519.pub,请将其替换为你的公钥文件名(如 id_rsa.pub)。

请我喝杯咖啡吧~

支付宝
微信