- 生成公钥和私钥
ssh-keygen
按三下ENTER
公私钥默认保存在 .ssh,文件夹中
cd .ssh - 发送公钥给另一台电脑
ssh-copy-id 用户名@ip
然后通过ssh链接就不需要输入密码了
tips:
- windows 没有 ssh-copy-id 命令
- 解决办法:powershell输入下面命令就可以使用 ssh-copy-id 了
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"
}
}