当前位置:   article > 正文

Redhat8 ssh免密登陆以及http配置实验_/root/.ssh/id_rsa

/root/.ssh/id_rsa

一、实验要求:

1.ssh免密登录:准备两台Linux虚拟机,第一台可以免密登录到第二台机器

2.ssh禁止root用户远程登录  

3.http:配置基于不同IP的访问不同的站点,要求默认首页文件为 first.html

二、实验准备

两台Redhat8虚拟机,ip配置如下

服务端:

客户端:

三、实验过程:

1.ssh免密登录

服务端:

配置服务端配置文件  

  1. [root@server ~]# vim /etc/ssh/sshd_config
  2. Port 22 #指定端口
  3. PubkeyAuthentication yes
  4. #PasswordAuthentication yes

客户端:

制作秘钥

  1. [root@haha ~]# ssh-keygen -t RSA
  2. Generating public/private RSA key pair.
  3. Enter file in which to save the key (/root/.ssh/id_rsa):
  4. /root/.ssh/id_rsa already exists.
  5. Overwrite (y/n)? y
  6. Enter passphrase (empty for no passphrase):
  7. Enter same passphrase again:
  8. Your identification has been saved in /root/.ssh/id_rsa.
  9. Your public key has been saved in /root/.ssh/id_rsa.pub.
  10. The key fingerprint is:
  11. SHA256:cjMRTrUZNMSDo/Jv2pqrKYJF9ZfWRc732Sc2JPmQlN4 root@haha
  12. The key's randomart image is:
  13. +---[RSA 3072]----+
  14. |        o**.o.   |
  15. |    .  oo.oOoo   |
  16. |   . . .o+o+B.o  |
  17. |  . . o +.. .*E.o|
  18. | .   o.oS     =.+|
  19. |  .   .o o   . o.|
  20. |..     .         |
  21. |o .  . oo        |
  22. | . .o.==.        |
  23. +----[SHA256]-----+

客户端发送公钥

  1. [root@haha ~]# ssh-copy-id -i 192.168.239.200
  2. /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
  3. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  4. /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
  5. Password:
  6. Password:
  7. Number of key(s) added: 1
  8. Now try logging into the machine, with:   "ssh '192.168.239.200'"
  9. and check to make sure that only the key(s) you wanted were added.

服务器端查看秘钥是否收到


测试:
用户登录登录成功


2.ssh禁止root用户远程登录
/etc/ssh/sshd_config 配置文件中加入下面这条指令
denyusers root #创建黑名单拒绝某个用户访问
测试:
使用root用户登录

无法登陆


3.http:配置基于不同IP访问不同的站点,要求默认首页文件为 first.html

添加一个新的ip地址

  1. [root@server ~]# nmcli c modify ens160 +ipv4.addresses 192.168.239.10/24
  2. [root@server ~]# nmcli connection up ens160

创建两个网页文件根目录,并定义网页内容

  1. [root@server ~]# mkdir -pv /www/ip/{10,200}
  2. [root@server ~]# echo this is 10 > /www/ip/10/first.html
  3. [root@server ~]# echo this is 200 > /www/ip/10/first.html

定义基于不同ip地址来访问网站的配置文件

  1. [root@server ~]# cd /etc/httpd/conf.d
  2. [root@server conf.d]# vim myhosts.conf
  3. <Directory "/www/ip">
  4.         AllowOverride None
  5.         Require all granted
  6. </Directory>
  7. <VirtualHost 192.168.239.10:80 >
  8.         DocumentRoot "/www/ip/10"
  9.         ServerName 192.168.239.10
  10. </VirtualHost>
  11. <virtualHost 192.168.239.200:80 >
  12.         DocumentRoot "/www/ip/200"
  13.         ServerName 192.168.239.200
  14. </VirtualHost>

编辑httpd主配置文件

  1. [root@server ~]# vim /etc/httpd/conf/httpd.conf
  2. <IfModule dir_module>
  3.     DirectoryIndex index.html home.html first.html
  4. </IfModule>

重启httpd服务

[root@server ~]# systemctl restart httpd

客户机基于ip访问http服务

使用主机浏览器访问http服务

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/187748
推荐阅读
相关标签
  

闽ICP备14008679号