Linux-免密ssh登陆
Posted xjshao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux-免密ssh登陆相关的知识,希望对你有一定的参考价值。
IP要能ping通
关闭防火墙
[[email protected] tdd]# systemctl stop firewalld
[[email protected] tdd]# systemctl disable firewalld
[[email protected] tdd]# vim /etc/selinux/config
修改SELINUX=disabled
[[email protected] tdd]# reboot
修改hostname
[[email protected] tdd]# uname -n
localhost.localdomain
修改配置文件 /etc/hostname 保存退出
[[email protected] tdd]# vim /etc/hostname
master
同步系统时间
[[email protected] tdd]# date
Fri Mar 29 04:50:21 CST 2019
[[email protected] tdd]# hwclock
Fri 29 Mar 2019 04:50:27 AM CST -0.666422 seconds
[[email protected] tdd]# hwclock -w
[[email protected] tdd]# ntpdate time.nist.gov
28 Mar 20:50:47 ntpdate[2847]: step time server 132.163.96.2 offset -28799.219966 sec
[[email protected] tdd]# hwclock -w
[[email protected] tdd]# date
Thu Mar 28 20:51:23 CST 2019
如果上面time.nist.gov服务器同步不了,可以换下面几个时间服务器试试:
time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org
在每台机器的/etc/hosts文件中添加如下内容:
[[email protected] tdd]# vim /etc/hosts
192.168.44.10 master
192.168.44.11 slave1
192.168.44.12 slave2
在master上操作:
首先生成密钥对
[[email protected] ~]# ssh-keygen -t rsa (提示时,直接回车即可)
导入本机
[[email protected] .ssh]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
再将master自己的公钥拷贝并追加到slave1、slave2的授权列表文件authorized_keys中
[[email protected] ~]# ssh-copy-id -i id_rsa [email protected]
[[email protected] ~]# ssh-copy-id -i id_rsa [email protected]
在slave*上操作:
同master只是@后是其他的机器
测试
master:
[[email protected] .ssh]# ssh slave2
Last failed login: Fri Mar 29 05:08:05 CST 2019 on pts/0
There were 2 failed login attempts since the last successful login.
Last login: Thu Mar 28 21:18:56 2019
[[email protected] ~]# ssh slave1
Last failed login: Thu Mar 28 21:24:44 CST 2019 from slave2 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Thu Mar 28 21:21:04 2019 from master
[[email protected] ~]# ssh master
Last login: Thu Mar 28 21:12:29 2019
[[email protected] ~]#
slave1:
[[email protected] .ssh]# ssh slave2
Last failed login: Fri Mar 29 05:08:05 CST 2019 on pts/0
There were 2 failed login attempts since the last successful login.
Last login: Thu Mar 28 21:30:35 2019 from master
[[email protected] ~]# ssh master
Last login: Thu Mar 28 21:27:28 2019 from slave1
[[email protected] ~]# ssh slave1
Last login: Thu Mar 28 21:27:23 2019 from slave2
[[email protected] ~]#
slave2:
[[email protected] .ssh]# ssh slave1
Last login: Thu Mar 28 21:28:15 2019 from master
[[email protected] ~]# ssh master
Last login: Thu Mar 28 21:28:08 2019 from slave2
[[email protected] ~]# ssh slave2
Last failed login: Fri Mar 29 05:08:05 CST 2019 on pts/0
There were 2 failed login attempts since the last successful login.
Last login: Thu Mar 28 21:31:21 2019 from slave1
[[email protected] ~]#
[[email protected] ~]# exit
logout
Connection to slave2 closed.
[[email protected] ~]# exit
logout
Connection to master closed.
[[email protected] ~]# exit
logout
Connection to slave1 closed.
[[email protected] .ssh]#
以上是关于Linux-免密ssh登陆的主要内容,如果未能解决你的问题,请参考以下文章