加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux-免密ssh登陆

发布时间:2020-12-14 02:08:56 所属栏目:Linux 来源:网络整理
导读: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 修改hostna

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

在每台机器的/etc/hosts文件中添加如下内容:

[[email?protected] tdd]# vim /etc/hosts
192.168.44.10 master
192.168.44.11 slave1
192.168.44.12 slave2

同步系统时间

[[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

ssh互信

在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只是@后是其他的机器的hostname

  • 这里用hostname是因为在hosts文件中配置了映射

测试

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]#

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读