SSH 远程免密登录
- 密钥对生成
ssh-keygen -t rsa
- 如果已经存在了,id_rsa,先将其改名,一路回车就行
- 将公钥上传
ssh-copy-id lovecc@192.168.81.131
- windows 会报错 ssh-copy-id 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" } }
- 配置别名(config) 使用别名登录
Host lovecc-4 # 别名 HostName 192.168.81.131 #ip User lovecc # user IdentityFile C:/Users/youlingdada/.ssh/id_rsa_lovecc_four # id_rsa 路径必须用绝对路径,不然在vscode 或者其他目录下,还是会要求输入密码 Host github.com HostName github.com User youlingdada IdentityFile C:/Users/youlingdada/.ssh/id_rsa_git
- 将对应的id_ras 改名后,就可以将原来的id_rsa改回去了,但是也可以像我这样,直接将原来的rsa也改了,配置一下
- 登录
ssh lovecc-4
- 引用参考
https://blog.csdn.net/Defiler_Lee/article/details/116278442