配置Centos/Ubuntu免密登录
配置Centos/Ubuntu免密登录
powershell 中的解决方案:
- 创建密钥对:
ssh-keygen -t rsa
- 将生成的公钥复制到目标服务器的authorized_keys文件中:
type ~/.ssh/id_rsa.pub | ssh user@host 'cat >> ~/.ssh/authorized_keys'
- 测试登录:
ssh user@host
使用 ssh-copy-id 命令:
ssh-copy-id user@192.168.0.1
如果发现无法识别 ssh-copy-id,先在pwsh中定义这个函数:(复制以下内容到pwsh中执行即可,当前pwsh进程有效)
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"
}
}
浙公网安备 33010602011771号