openssh 免用戶名/密碼/服務器地址,登錄遠程服務器
阿新 • • 發佈:2019-01-31
服務 本地配置 config 密碼 keys span cal con 生成
- 原理
在 local 本地創建一對公、私鑰,將公鑰放到 remote 遠程服務器,local 本地保存私鑰;
遠程登錄時,拿本地的私鑰加密,遠程服務器拿公鑰解密。
- 在本地創建公、私鑰
ssh-keygen -t rsa
會在本地的 ~/.ssh 目錄生成公、私鑰文件:
id_rsa.pub // 公鑰
id_rsa. // 私鑰
- 將公鑰 id_rsa.pub 存入遠程服務器的 ~/.ssh/authorized_keys 文件中
ssh root@url "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
- 本地配置 ~/.ssh/config 文件
配置遠端服務器及指定本地的私鑰,若有多個遠程服務器,就多配幾個
Host 188 # ssh <name> 的 name HostName 192.168.0.188 # 遠端服務器 IP User root # 遠端服務器用戶名 Port 22 IdentityFile ~/.ssh/id_rsa # 私鑰位置
- 登錄遠端服務器
比如上例:
ssh 188 # ~/.ssh/config 裏配置的 Host
openssh 免用戶名/密碼/服務器地址,登錄遠程服務器