生成公钥密钥对:ssh-keygen -t rsa(客户端)
上传公钥到服务端:ssh-copy-id 服务端用户名@服务端ip地址
如果遇到以下问题:
ssh-copy-id : 无法将“ssh-copy-id”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。
解决方法:
在终端先执行以下内容:
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 服务端用户名@服务端ip地址