RHCE第二次作业

简介: RHCE第二次作业

1.实现ssh免密登录

主机client免密登录主机server

(1)保证sshd服务开启

[root@client .ssh]# systemctl start sshd
[root@client .ssh]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor pre>
   Active: active (running) since Tue 2022-07-26 21:02:26 CST; 9min ago

(2)在/root/.ssh/目录下生成一对私钥和公钥

[root@client .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:/coLWhCCXteokxoqGQEXqZcMBM6QluWORcRrgkE/YsA root@client
The key's randomart image is:
+---[RSA 3072]----+
|X+B*             |
|XE=o   o         |
|+X.*+ + .        |
|++O+.= . .       |
|.o=.+ . S .      |
| + o . .   .     |
|+ .     o   .    |
|.      o o .     |
|      .   +.     |
+----[SHA256]-----+
 
[root@client .ssh]# ll /root/.ssh
total 8
-rw-------. 1 root root 2602 Jul 26 21:19 id_rsa
-rw-r--r--. 1 root root  565 Jul 26 21:19 id_rsa.pub 

(3)将client的公钥写入server的/root/.ssh/authorized_keys文件中

[root@client .ssh]# ssh-copy-id root@192.168.5.128    # 若没有/root/.ssh/authorized_keys文件则会自动创建
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.5.128 (192.168.5.128)' can't be established.
ECDSA key fingerprint is SHA256:DfhFDt2EwYv+iqoMPJSjQ7AcULIMg+o3BDENpQrTioQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes    # 输入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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.5.128's password:             # 输入server主机root用户的密码
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'root@192.168.5.128'"
and check to make sure that only the key(s) you wanted were added.

(4)在client登录server主机——无需输入密码,实现免密登录

[root@client .ssh]# ssh 192.168.5.128
Activate the web console with: systemctl enable --now cockpit.socket
 
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
 
Last login: Tue Jul 26 21:06:12 2022 from 192.168.5.1
[root@server ~]# 
 
[root@server ~]# ll /root/.ssh
total 4
-rw------- 1 root root 565 Jul 26 21:26 authorized_keys


ssh设置只允许student1, student2用户登录

(1)创建student1、student2用户

[root@server ssh]# useradd student1 -p redhat
[root@server ssh]# useradd student2 -p redhat

(2)修改配置文件/etc/ssh/sshd_config

[root@server ssh]# vim sshd_config 
…………
# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
AllowUsers student1 student2        #在最后一行添加此内容

(3)重启sshd服务

[root@server ssh]# systemctl restart sshd

(4)登录测试

[C:\~]$ ssh student1@192.168.5.128            #登录成功
 
 
Connecting to 192.168.5.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
 
Activate the web console with: systemctl enable --now cockpit.socket
 
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
 
Last failed login: Tue Jul 26 21:49:08 CST 2022 from 192.168.5.1 on ssh:notty
There were 8 failed login attempts since the last successful login.
/usr/bin/xauth:  file /home/student1/.Xauthority does not exist
[student1@server ~]$ 
 
[C:\~]$ ssh student2@192.168.5.128                #登录成功
 
 
Connecting to 192.168.5.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
 
Activate the web console with: systemctl enable --now cockpit.socket
 
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
 
/usr/bin/xauth:  file /home/student2/.Xauthority does not exist
[student2@server ~]$ 
 
[C:\~]$ ssh redhat@192.168.5.128                    #其他用户如redhat无法登录
 
 
Connecting to 192.168.5.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Connection closing...Socket close.
 
Connection closed by foreign host.
 
Disconnected from remote host(192.168.5.128:22) at 21:57:32.
 
Type `help' to learn how to use Xshell prompt.
 
[C:\~]$ ssh root@192.168.5.128                    #root用户也无法登录
 
 
Connecting to 192.168.5.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Connection closing...Socket close.
 
Connection closed by foreign host.
 
Disconnected from remote host(192.168.5.128:22) at 21:56:06.
 
Type `help' to learn how to use Xshell prompt.
 
相关文章
|
Linux
centos 8 换阿里源
centos 8 换阿里源
6271 0
|
Java API Spring
【一】springboot整合swagger
【一】springboot整合swagger
495 0
|
Ubuntu 安全 Linux
Linux(34)Rockchip RK3568 Ubuntu22.04和Debian 10上配置远程桌面工具
Linux(34)Rockchip RK3568 Ubuntu22.04和Debian 10上配置远程桌面工具
2604 0
33activiti - 并行网关(parallelGateWay)
33activiti - 并行网关(parallelGateWay)
991 0
|
弹性计算 IDE Shell
你好,云起实验室
本教程帮助开发者了解云起实验室。
|
数据库
MyBatisPlus-乐观锁概念及实现步骤
MyBatisPlus-乐观锁概念及实现步骤
419 0
|
缓存 NoSQL Redis
Redis缓存雪崩、缓存穿透、缓存击穿解决方案详解
本文详解Redis缓存雪崩、穿透与击穿问题及其解决方案,涵盖差异化过期时间、互斥锁、布隆过滤器等策略,提升系统稳定性与性能。
1047 0
Redis缓存雪崩、缓存穿透、缓存击穿解决方案详解
|
存储 人工智能 Serverless
为你的网站打造一个AI助手
通过简单四步,即可在网站中集成AI助手,提升客户咨询体验。首先点击“立即部署”,创建大模型问答应用并获取API凭证;接着利用函数计算快速搭建示例网站;随后解除代码注释,引入AI助手;最后配置知识库,上传文档并建立索引,使AI助手能提供更精准的回答。新用户可享受免费额度,降低初期成本。
1026 0
|
安全 数据安全/隐私保护 网络架构
ensp中nat地址转换(静态nat 动态nat NAPT 和Easy IP)配置命令
ensp中nat地址转换(静态nat 动态nat NAPT 和Easy IP)配置命令
3891 0
|
监控 NoSQL Java
【面试高频 time:】SpringBoot整合Redisson实现分布式锁
【面试高频 time:】SpringBoot整合Redisson实现分布式锁
285 0