在很多软件安装的时候都有这些需求,因此在这里一起讲一下

修改主机名

简单的使用 hostnamectl 命令就好了

hostnamectl set-hostname NAME

免密认证

准备工作,修改主机文件

/etc/hosts
[root@node1 .ssh]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.79.200 node1
192.168.79.202 node2
192.168.79.204 node3

在每个节点的/root/.ssh目录下执行(连按三次回车就好)

ssh-keygen -t rsa
[root@node1 .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:EZ1TYD9Hu7qQO+lKsOPGGu2ym5pbMUWR0psjBW7XVwM root@node1
The key's randomart image is:
+---[RSA ]----+
| .ooo..E=+ . |
| ...+. o+o o . |
| ooooo ..o o |
| ..o+ o o . |
| o...S . |
| + o . . |
| o.+ . o.. |
| o.=oo oo . |
| +o=*o .oo.. |
+----[SHA256]-----+

然后在node1上执行

cat id_rsa.pub >> authorized_keys

登录其余主机,将公钥文件全部拷贝到node1的authorized_keys中,如node3节点:

[root@node3 .ssh]# ssh-copy-id -i node1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node1 (192.168.79.200)' can't be established.
ECDSA key fingerprint is SHA256:AdOUf9OIf3q4Ks7q8nj0agFtFIFdB1BGtlk8SkYImmo.
ECDSA key fingerprint is MD5::b6:be:a0:bb:f3:7a:e5:2c:6b:4a:c0:a4:7f::.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@node1's password: Number of key(s) added: Now try logging into the machine, with: "ssh 'node1'"
and check to make sure that only the key(s) you wanted were added.

此时查看node1节点的authorized_keys文件可以看到已经全部加进来了

[root@node1 .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3BQUX3qQJadEaBv8IGNh1aqIKIfT/9IkqZGCfx9UEFQ4kGOdpNay355YLKUOMNbjYtFSyVA0M2jkVopFPNlhEh7S/dIgYslgjEL7rtwl8evK9FI6cIkKbjWQWbpjdLgBrvvKhAPUBwhpfoUqUyzr+wtwSzgIJV8/C651OsRP4frtVruJj6qHBE+Rb++mUbs2sGj7h8NNrtWgIHJupFqrg35F7VcVGQe4LMdm3xTDXH0b/a15LosLtg7DQOngCXuJ4iL7qVIHHXqWv2Khv+Gw/PP6fvfPD29v8KCpjSq9Yk+O44LeM4mJE39TsHY+ASxSae4surdomcCCVQoeJ7tbF root@node1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC34kQ98T/x4ex1FvNnCEC1wquxJeaMTjzWuySP33CHXHK0QpvJMg5Y1t7v9sItuVCtJac0Z932Qd0E/QnBWCNuq548JmZeIWgzdXiI+G8MLSk32GJmXig9X4THUWpcRm+qmo9ZXTImqW0C1srRNr7cQ8AtViCooxFcF7s410D1XBLza7V+Key+GTrYZNQV+cXQMX643TJl/TQaOzJamDsPZnH9f9E4q1Ux0I47IiPJBMjLonox/Bqf8W+qDgQKFA6zWrebb7YWdMbS4x8hHN0+SIeoMpLYdUNy18XCREZEYd4aWJs4v8RRsrdBaKMA1LtELNktapFqVTWtc9fFN51f root@node2
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1+6ZqI1mU2mns17pNWoPkmzSExYy14gJI5elUeM91LLjxlKMz7TWofJPJg/s2hSuu3v9db3PwzYhZenCEJ6k6R8e+iUlu65QEgvQWhsLzbQW5UAXdqKzhhC6DsaYLUZbnfaCIMNvzWo6rUcaRnKZFVAw+scxxFasHJnjQmiAZg0uL8iCT1Cghu9CwqAF2UFxCCSt6rso6l71YUZAsUMtiCS1wA/D5+9rYHkXijgTsMK3nlklQNJ9QPWz/AHgTs0N59STpWJ89KMxCRZfWgvkwzoajYMK4OeUV9HxSZuzwuIOR3Rek4YB2BN0VdfQZZxO07pgnPi/OawswojkxgRYX root@node3

修改权限后把authorized_keys文件拷贝到其余节点,此时所有节点免密认证成功

[root@node1 .ssh]# chmod  authorized_keys
[root@node1 .ssh]# scp authorized_keys node2:`pwd`
The authenticity of host 'node2 (192.168.79.202)' can't be established.
ECDSA key fingerprint is SHA256:AdOUf9OIf3q4Ks7q8nj0agFtFIFdB1BGtlk8SkYImmo.
ECDSA key fingerprint is MD5::b6:be:a0:bb:f3:7a:e5:2c:6b:4a:c0:a4:7f::.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,192.168.79.202' (ECDSA) to the list of known hosts.
root@node2's password:
authorized_keys % .8KB/s :
[root@node1 .ssh]# scp authorized_keys node3:`pwd`
The authenticity of host 'node3 (192.168.79.204)' can't be established.
ECDSA key fingerprint is SHA256:AdOUf9OIf3q4Ks7q8nj0agFtFIFdB1BGtlk8SkYImmo.
ECDSA key fingerprint is MD5::b6:be:a0:bb:f3:7a:e5:2c:6b:4a:c0:a4:7f::.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node3,192.168.79.204' (ECDSA) to the list of known hosts.
root@node3's password:
authorized_keys % .8KB/s :
[root@node1 .ssh]#

关闭防火墙

一般来说关闭firewalld服务和selinux

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld #关闭selinux
使用getenforce来查看是否开启,如果开启
使用setenforce 0关闭 # 永久关闭selinux
vim /etc/sysconfig/selinux
将SELINUX=enforcing改为disabled

linux修改主机名+免密认证+关闭防火墙的更多相关文章

  1. linux修改主机名的方法

    linux修改主机名的方法 用hostname命令可以临时修改机器名,但机器重新启动之后就会恢复原来的值. #hostname   //查看机器名#hostname -i  //查看本机器名对应的ip ...

  2. linux修改主机名(hostname)转载

    Linux修改主机名的方法 用hostname命令可以临时修改机器名,但机器重新启动之后就会恢复原来的值. #hostname   //查看机器名#hostname -i  //查看本机器名对应的ip ...

  3. linux修改主机名,关闭图形化界面,绑定ip地址,修改ip地址

    1关闭图形化界面 vi /etc/inittab 改成id:3:initdefault: 注意:不要选0或6 2.修改主机名 vi /etc/sysconfig/network 修改即可 3,修改ip ...

  4. linux修改主机名

    查看机器名:uname -a 修改机器名: redhat中修改主机名 第一步:#hostname oratest 第二步:修改/etc/sysconfig/network中的hostname 第三步: ...

  5. Linux修改主机名!(图文)

    本篇作为之前的补充篇,如果想修改自己的主机名,方便老师检查作业是否是自己做的,可以用修改主机名的方法,那么怎么修改呢? 一. 使用hostname命令 比如我现在的主机名是haozhikuan-hbz ...

  6. Linux修改主机名方法

    [root@lyx ~]# vim /etc/hosts   vim代表修改,进入hosts文件进行添加192.168.10.128 hadoop128 [root@lyx ~]# hostname ...

  7. CentOS Linux 修改主机名

    一.CentOS5 修改主机名 二.CentOS6 修改主机名 三.CentOS7 修改主机名 静态的(Static hostname)        "静态"主机名也称为内核主机 ...

  8. Redhat Linux 修改主机名(HOSTNAME)

    hostname #查看当前主机的主机名hostname NEWHOSTNAME #临时修改当前主机名 修改主机名vi /etc/sysconfig/network #通过配置文件修改主机名NETWO ...

  9. Linux 修改主机名 和 ip 映射关系

    1. 修改主机名 vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=hadoop 2. 修改主机名和IP的映射关系 vim /etc/hosts 1 ...

随机推荐

  1. 手机app抓包

    简介 爬虫是cs架构中的c端 原理是模拟浏览器向服务器发送请求 如果要爬取手机APP的数据,APP也是服务端与浏览器性质相同 我们只要获取到手机APP给服务器发送数据 并加以分析就能模拟它的请求 从而 ...

  2. MongoDB --- 01. 安装, 第三方客户端

    一.安装 1.选择默认安装 ①完成后进入目录查看 "C:\Program Files\MongoDB\Server\3.4\bin" ② 配置环境变量 ③ 在 c盘创建目录(数据库 ...

  3. 生信工具汇总--OMICtools

    各种生信工具: https://omictools.com/

  4. libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

    In Xcode 9 and Swift 4: Print exception stack to know the reason of the exception: Go to show break ...

  5. CentOS7 DHCP 服务搭建

    一.实验环境 1.VMware12.俩台Linux(Ser  和  Client ).DHCP安装包. 二.操作流程 1.安装DHCP 2.配置DHCP的配置文件:  /etc/dhcp/dhcpd. ...

  6. C# 封装SDK 获取摄像头的水平角度和垂直角度

    最近需要做一个C#版本的控制终端,控制摄像头,获取摄像头的水平角度和垂直角度 获取当前摄像头的角度,需要调用一个名为NET_DVR_GetDVRConfig的bool类型的函数 在C++中,函数定义: ...

  7. composer学习总结

    composer 简介:是php用来管理依赖(dependency)关系的工具,工具包地址:https://packagist.org 下载地址:https://getcomposer.org/  安 ...

  8. Mysql 索引之B+tree

    InnoDB使用的是聚簇索引,将主键组织到一棵B+树中,而行数据就储存在叶子节点上,若使用"where id = 14"这样的条件查找主键,则按照B+树的检索算法即可查找到对应的叶 ...

  9. Phpstorm数组对齐设置

    进入 Editor > Code Style > PHP > Wrapping and Braces , 勾选 Align consecutive assignments 和 Ali ...

  10. Java面试题之Java基础

    1. JDK 和 JRE 有什么区别? JRE(JavaRuntimeEnvironment,Java运行环境),也就是Java平台.所有的Java 程序都要在JRE下才能运行.普通用户只需要运行已开 ...