用 ssh-copy-id 一键安装 SSH 公钥

不用再手动 cat >> authorized_keys——ssh-copy-id 把公钥推到服务器并顺手修正权限,一条命令搞定免密登录。

LinuxSSH 远程连接认证密钥低风险
执行 `ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server`,输入一次密码,之后登录就自动使用密钥。

01命令

命令
$ ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server

02作用说明

ssh-copy-id 会把你指定的公钥追加到服务器的 ~/.ssh/authorized_keys,并且会设置 sshd 静默要求的正确文件和目录权限。`-i` 可以精确选择要安装的密钥(记得写 `.pub` 文件),而不是把所有身份一股脑推上去。服务器用了非标准端口时按 SSH 风格传:`ssh-copy-id -p 2222 user@server`,或用 `-o 'Port 2222'`。

03风险

风险低风险
使用条件ssh-copy-id; password access to the target account for the first copy

04撤销

撤销
$ Remove the appended line from ~/.ssh/authorized_keys on the server.

05来源

最后验证: 2026-09-17 · 分类: 网络