网上有些说得太复杂了。简单点说,就是本机生成密钥公钥对,把公钥发给目标主机即可。
-
ssh-keygen -t rsa 生成密钥公钥
-
ssh-copy-id xxx@xxx.net 把公钥发给目标主机
2023.2.16
windows无法使用ssh-copy-id解决办法
1.在powershell中执行脚本
{IP-ADDRESS-OR-FQDN}写ip地址或者域名或者用户@ip地址或域名
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"
2.powershell下执行脚本
function ssh-copy-id([string]$userAtMachine, $args){
$publicKey = "$ENV:USERPROFILE" + "/.ssh/id_rsa.pub"
if (!(Test-Path "$publicKey")){
Write-Error "ERROR: failed to open ID file '$publicKey': No such file"
}
else {
& cat "$publicKey" | ssh $args $userAtMachine "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"
}
}
然后就可以使用ssh-copy-id
原文地址:https://blog.csdn.net/qq_45624685/article/details/122631083