远程登录与web服务器得到配置
要想第一台虚拟机可以免密登录到第二台虚拟机,需要将第一台虚拟机产生的公钥放置在第二台虚拟机的/root/.ssh/authorized_keys文件下(注意.ssh目录下是没有authorized_keys文件的,需要我们自己创建)。将目录切换到/etc/httpd/conf.d/下,新建文件test.conf(问价名可随意取,后缀必须是以.conf结尾),并进入编辑。第一台虚拟机禁止root远程
1.ssh免密登录:准备两台Linux虚拟机,第一台可以免密登录到第二台机器 ssh禁止root用户远程登录
首先,开启两台虚拟机,rhcsa为第一台机器,rhsic1作为第二台机器。并起到那个sshd。
要想第一台虚拟机可以免密登录到第二台虚拟机,需要将第一台虚拟机产生的公钥放置在第二台虚拟机的/root/.ssh/authorized_keys文件下(注意.ssh目录下是没有authorized_keys文件的,需要我们自己创建)。
#生成一个2048B大小rsa类型的认证密钥
[root@rhcsa2 ~]# ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
#输入要在其保存的密钥文件,默认文件为/root/.ssh/id_rsa
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:I2gtHO/86awQMGpvt1Pc1zOgkVx67USbgctpsR0tOYs root@rhcsa2
The key's randomart image is:
+---[RSA 2048]----+
| . o |
| + B . |
| o . . = X O |
| . + = = E B |
|.. * = S = = |
|. .. = + + . = |
| o..+ . o |
| . .o.o . |
| .oo= |
+----[SHA256]-----+
切换路径为/root/.ssh/id_rsa,查看文件是否存在
[root@rhcsa2 ~]# cd /root/.ssh/
[root@rhcsa2 .ssh]# ls -l
total 12
-rw------- 1 root root 1823 Oct 3 00:11 id_rsa #私钥
-rw-r--r-- 1 root root 393 Oct 3 00:11 id_rsa.pub #共钥
-rw-r--r-- 1 root root 177 Sep 24 13:27 known_hosts
将rhcsa虚拟机产生的公钥复制到rhsic1虚拟机的/root/.ssh/目录下。
[root@rhcsa2 .ssh]# scp /root/.ssh/id_rsa.pub root@192.168.112.131:/root/.ssh/authorized_keys
root@192.168.112.131's password: #输入root用户密码
id_rsa.pub 100% 393 309.2KB/s 00:00
进入虚拟机rhsic1 /root/.ssh/目录下查看是否有文件authorized_keys生成。
[root@hh ~]# cd /root/.ssh/
[root@hh .ssh]# ls -l
total 4
-rw-r--r--. 1 root root 393 Oct 3 00:23 authorized_keys
打开authorized_keys文件查看密钥
[root@hh .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGC0FwASvSCqCzKippepA83LtmB9wWf9fTUTN7u451I8pB6r+D/vVwgSppPdy5rmtqUcTJcnDqrJ19NKDO6z62WMIpZ2xunI0wDD75X/Nl1ZLtTlAHKTHReHDfz5bK4D6UKJsCOhFF7Kk1VKgUehMU9drX+djOBmGLSBsKKvtkCR2kj8fe8+BmEIenBoeWaxn/o0mfF2i3b9ZjFGywHsr4EWdQZqH4B3d53Yb8oD1zKYfuQHQcxIBiwExDUgJRWH5uqGDGkYVI/oMR2LTyiDd8XvyikOjMWpTI+gH0PGota2kUCiJb1mA29Zs8ZFnZLjVNdwBjU0pos4BFJBlIWICb root@rhcsa2
说明密钥已经复制成功
进行登录测试
[root@rhcsa2 .ssh]# ssh root@192.168.112.131 #远程登录
Activate the web console with: systemctl enable --now cockpit.socket
Last failed login: Mon Oct 3 00:22:53 CST 2022 from 192.168.112.132 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Mon Oct 3 00:10:51 2022 from 192.168.112.1
[root@hh ~]#
第一台虚拟机禁止root远程进行登录第二台虚拟机,需要对rhsic1虚拟机的/etc/ssh/sshd_conf配置文件进行修改。
#编辑配置文件
[root@hh ~]# vim /etc/ssh/sshd_config
将配置文件中的 PermitRootLogin yes修改成 PermitRootLogin no
再次进行远程登录
[root@hh ~]# exit #退出远程灯登录,进入rhcsa虚拟机
logout
Connection to 192.168.112.131 closed.
[root@rhcsa2 .ssh]# ssh root@192.168.112.131 # 进行远程登录
root@192.168.112.131's password: #不仅需要输入密码,而且输入正确密码也无法进行登录
Permission denied, please try again.
root@192.168.112.131's password:
2.http:配置基于不同IP的访问不同的站点,要求默认首页文件为 first.html
配置基于不同IP的访问不同的站点,需要对httpd的配置文件进行修改,但是由于总是修改主配置文件的话,会导致主主配置文件越来越大,导致修改或增加配置的效率会低。所以我们可以conf.d目录下,新建一个配置文件来对应此功能。
首先我们需要开启虚拟机并且启动httpd程序。
[root@rhcsa2 ~]# systemctl restart httpd
将目录切换到/etc/httpd/conf.d/下,新建文件test.conf(问价名可随意取,后缀必须是以.conf结尾),并进入编辑
[root@rhcsa2 ~]# cd /etc/httpd/conf.d
[root@rhcsa2 conf.d]# vim test.conf
注意题目要求中还提到,基于不同的IP,所以我们还需要增加虚拟机中的IP
[root@rhcsa2 conf.d]# nmcli c modify ens160 +ipv4.addresses 192.168.112.100/24
[root@rhcsa2 conf.d]# nmcli c modify ens160 +ipv4.addresses 192.168.112.200/24
[root@rhcsa2 conf.d]# nmcli c up ens160 #重启
查看IP添加情况
[root@rhcsa2 conf.d]# ip a
我们进入test.conf文件进行编辑。
文件配置内容:
<Directory "/www/ip">
AllowOverride None
Require all granted
</Directory>
<VirtualHost 192.168.112.100:80>
DocumentRoot "/www/ip/100"
ServerName 192.168.112.100
</VirtualHost>
<VirtualHost 192.168.112.200:80>
DocumentRoot "/www/ip/200"
ServerName 192.168.112.200
</VirtualHost>
创建两个网页文件根目录,并定义网页内容
[root@rhcsa2 ~]# mkdir -p /www/ip/{100,200}
[root@rhcsa2 ~]# echo the ip is 100 > /www/ip/100/index.html
[root@rhcsa2 ~]# echo the ip is 200 > /www/ip/200/index.html
重启httpd协议:
[root@rhcsa2 ~]# systemctl restart httpd
[root@rhcsa2 ~]# curl 192.168.112.100
the ip is 100
[root@rhcsa2 ~]# curl 192.168.112.200
the ip is 200
[root@rhcsa2 ~]#
要求默认文件为frist.html,需要对主配置文件进行修改。
[root@rhcsa2 ~]# vim /etc/httpd/conf/httpd.conf
重启httpd程序
[root@rhcsa2 html]# systemctl restart httpd
进入目录 /var/www/html下,创建frist.html文件并对其配置
[root@rhcsa2 html]# echo This is server page > frist.html
更多推荐
所有评论(0)