1 |
ssh-keygen -t rsa |

1 2 3 4 5 6 7 8 9 10 11 |
cd .ssh cat id_rsa.pub >> authorized_keys 如果是root账号给644,普通账户给600 chmod 644 authorized_keys chmod 700 .ssh 然后将公钥拷贝到其他机器 cd .ssh ssh-copy-id [目标机器] #然后登陆 ssh [目标机器] |
也可以用私钥在其他机器登录到这台机器,私钥免密config配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
同样是在.ssh中配置,如果没有config文件请新建,权限给600 vim config HostName 192.168.6.121 User root Port 22 IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes HostName 192.168.6.122 User root Port 22 IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes HostName 192.168.6.123 User root Port 22 IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes |
新版本config写法(新版是config文件)
1 |
vim config |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Host 192.168.0.205 HostName 192.168.0.205 User root Port 22 IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Host 192.168.0.212 HostName 192.168.0.212 User root Port 22 IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Host 192.168.0.206 HostName 192.168.0.206 User root Port 22 IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes |
保存后赋予600权限
然后使用ssh [ip] 免密登录

- 本文固定链接: https://www.yoyoask.com/?p=3838
- 转载请注明: shooter 于 SHOOTER 发表