用 ssh-copy-id 一键安装 SSH 公钥
不用再手动 cat >> authorized_keys——ssh-copy-id 把公钥推到服务器并顺手修正权限,一条命令搞定免密登录。
执行 `ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server`,输入一次密码,之后登录就自动使用密钥。
01命令
命令
$ ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server02作用说明
ssh-copy-id 会把你指定的公钥追加到服务器的 ~/.ssh/authorized_keys,并且会设置 sshd 静默要求的正确文件和目录权限。`-i` 可以精确选择要安装的密钥(记得写 `.pub` 文件),而不是把所有身份一股脑推上去。服务器用了非标准端口时按 SSH 风格传:`ssh-copy-id -p 2222 user@server`,或用 `-o 'Port 2222'`。
03风险
04撤销
撤销
$ Remove the appended line from ~/.ssh/authorized_keys on the server.05来源
- ssh-copy-id(1) — use locally available keys to authorise logins依据: Documents ssh-copy-id installing public keys into a remote account's authorized_keys and the -i option to select the key.
最后验证: 2026-09-17 · 分类: 网络