Linux-CentOS7 SSH免登陆



配置三台服务器,如下:

Linux-CentOS7 SSH免登陆

在三台机器(node1\node2\node3)执行以下命令,生成公钥与私钥。

ssh-keygen -t rsa

执行该命令之后,按下三个回车即可,然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥),默认保存在/root/.ssh目录。

Linux-CentOS7 SSH免登陆

分配密钥

三台机器将拷贝公钥到node1机器,三台机器执行命令:

ssh-copy-id node1

Linux-CentOS7 SSH免登陆

将node1机器的公钥拷贝到其他机器上,在node1机器上指行以下命令,执行命令时,需要输入yes和对方的密码:

scp /root/.ssh/authorized_keys node2:/root/.ssh
scp /root/.ssh/authorized_keys node3:/root/.ssh

测试SSH免密登录

可以在任何一台主机上通过ssh 主机名命令去远程登录到该主机,输入exit退出登录

例如:在node1机器上,免密登录到node2机器上

ssh node1
exit

Linux-CentOS7 SSH免登陆

三台机器时钟同步

在node1虚拟机安装ntp并启动,安装ntp服务

yum -y install ntp
systemctl start  ntpd

设置ntpd的服务开机启动

#关闭chrony,Chrony是NTP的另一种实现
systemctl disable chrony
#设置ntp服务为开机启动
systemctl enable ntpd.service

编辑node1的/etc/ntp.conf文件

vim /etc/ntp.conf

在文件中添加如下内容(授权192.168.88.0-192.168.88.255网段上的所有机器可以从这台机器上查询和同步时间)。

restrict 192.168.88.0 mask 255.255.255.0 nomodify notrap

注释以下四行内容:(集群在局域网中,不使用其他互联网上的时间)。

server 0.centos.pool.ntp.org

server 1.centos.pool.ntp.org

server 2.centos.pool.ntp.org

server 3.centos.pool.ntp.org

删除下面的注释,如果没有这两行,请自己添加(当节点断开网络连接时,它仍然可以使用本地时间作为时间服务器,为集群中的其他节点提供时间同步)

[En]

Remove the comments from the following, and if you don’t have these two lines, add them yourself (when the node loses its network connection, it can still use local time as a time server to provide time synchronization for other nodes in the cluster)

server 127.127.1.0

fudge 127.127.1.0 stratum 10

restrict 192.168.88.0 mask 255.255.255.0 nomodify notrap

#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
#server 3.centos.pool.ntp.org

server 127.127.1.0
fudge 127.127.1.0 stratum 10

Linux-CentOS7 SSH免登陆

配置以下内容,保证BIOS与系统时间同步

vim /etc /sysconfig /ntpd

添加一行内容

SYNC_HWLOCK=yes

vim /etc/sysconfig/ntpd
SYNC_HWLOCK=yes

Linux-CentOS7 SSH免登陆

另外两台机器与192.168.88.161进行时钟同步,在node2和node3机器上分别进行以下操作。

crontab  -e

#添加以下内容:(每隔一分钟与node1进行时钟同步)
*/1 * * * * /usr/sbin/ntpdate 192.168.88.161

Original: https://www.cnblogs.com/LaoPaoEr/p/16273456.html
Author: 无昵称老炮儿
Title: Linux-CentOS7 SSH免登陆

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/523611/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球