百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

玩转Redhat Linux 8.0系列 | 管理用户密码

nanshan 2024-10-30 02:55 20 浏览 0 评论

素材来源:Redhat Linux 8.0培训教材《RH124》、《RH134》和《RH294》

玩了5-6年的Linux,现在再来温习一遍RHCE培训教材,按照指导完成实验并与大家分享。

附上汇总贴:玩转Redhat Linux 8.0系列 | 合集_热爱编程的通信人的博客-CSDN博客


1 从workstation,以student用户身份打开连接servera的SSH会话。

Bash
[student@workstation ~]$ ssh student@servera
student@servera's password: 
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: Sat May 20 20:53:37 2023 from 172.16.190.227
[student@servera ~]$

2 在servera上, 以student身份探索用户帐户的锁定和解锁。

2.1 以student身份, 使用管理权限锁定operator1帐户。

Bash
[student@servera ~]$ sudo usermod -L operator1
[sudo] password for student: 
[student@servera ~]$ 

2.2 尝试以operator1身份登录。这应该会失败。

[student@servera ~]$ su - operator1
Password: 
su: Authentication failure
[student@servera ~]$ 

2.3 解锁operator1帐户。

[student@servera ~]$ sudo usermod -U operator1
[student@servera ~]$ 

2.4 再次尝试以operator1身份登录。这应该会成功。

[student@servera ~]$ su - operator1
Password: 
[operator1@servera ~]$ 

2.5 从operator1用户的shell退出, 以返回到student用户的shell。

[operator1@servera ~]$ exit
logout
[student@servera ~]$ 

3 更改operator1的密码策略, 使其每90天要求创建新密码。确认已成功设置密码期限。

3.1 将operator1用户的密码的最长期限设为90天。

[student@servera ~]$ sudo chage -M 90 operator1
[student@servera ~]$

3.2 验证operator1用户的密码是否在更改后90天过期。

[student@servera ~]$ sudo chage -l operator1
Last password change                                    : May 20, 2023
Password expires                                        : Aug 18, 2023
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 7
[student@servera ~]$ 

4 强制operator1帐户在第一次登录时更改密码。

[student@servera ~]$ sudo chage -d 0 operator1
[student@servera ~]$ 

5 以operator1身份登录, 并将密码更改为forsooth123。设置密码后, 返回到student用户的shell。

5.1 以operator1身份登录, 并在提示时将密码更改为forsooth123。

[student@servera ~]$ su - operator1
Password: 
You are required to change your password immediately (administrator enforced)
Current password: 
New password: 
Retype new password: 
[operator1@servera ~]$ 

5.2 从operator1用户的shell退出, 以返回到student用户的shell。

[operator1@servera ~]$ exit
logout
[student@servera ~]$ 

6 将operator1帐户设置为从当天起180天后过期。提示:date -d "+180 days"为您提供从当前日期和时间起180天的日期和时间。

6.1 确定未来180天后的日期。将%F格式用于date命令以获取确切的值。

[student@servera ~]$ date -d "+180 days" +%F
2023-11-16
[student@servera ~]$ 

根据系统中的当前日期和时间,您可能会获得不同的值供以下步骤中使用。

6.2 将帐户设置为在上一步中显示的日期到期。

[student@servera ~]$ sudo chage -E 2023-11-16 operator1
[student@servera ~]$ 

6.3 验证是否已成功设置帐户到期日期。

[student@servera ~]$ sudo chage -l operator1
Last password change                                    : May 20, 2023
Password expires                                        : Aug 18, 2023
Password inactive                                       : never
Account expires                                         : Nov 16, 2023
Minimum number of days between password change          : 0
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 7
[student@servera ~]$

7 将所有用户的密码设置为自当前日期起180天后过期。使用管理权限编辑配置文件。

7.1 在/etc/login.defs中, 将PASS_MAX_DAYS设为180。通过文本编辑器打开文件时应使用管理权限。您可以使用sudo vim /etc/login.defs命令执行此步骤。

#       PASS_WARN_AGE   Number of days warning given before a password expires.
#
PASS_MAX_DAYS   180
PASS_MIN_DAYS   0

7.2 从servera注销。

[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$ 

相关推荐

ssh终端xshell日志查看命令(xshell怎么看日志)

现在我们云服务器运维较多用的是SSH工具,其中常用的包括PUTTY、XSHELL等,其实大同小异界面UI稍微不同,但是都可以进入远程连接。这里有朋友提到如何查看服务器的日志文件,这个其实和是否使用XS...

使用 Fail Ban 日志分析 SSH 攻击行为

通过分析`fail2ban`日志可以识别和应对SSH暴力破解等攻击行为。以下是详细的操作流程和关键分析方法:---###**一、Fail2ban日志位置**Fail2ban的日志路径因系统配置...

如何高效读取Linux日志文件?这些命令要熟记于心!

在Linux系统中,日志文件通常存储在/var/log目录下。比如,/var/log/syslog(或/var/log/messages,视发行版而定)记录系统整体事件,/var/log/a...

Windows服务器远程登录日志查询方法,linux查看登录日志方法

概述本文介绍Windows、Linux服务器查询系统的远程登录日志方法。根据服务器所使用的操作系统不同,有以下两种查询方法。Linux操作系统的登录日志查询通过远程连接登录Linux服务器,使用roo...

iptables防火墙如何记录日志(防火墙日志查看)

例如:记录所有ssh服务的登录的日志首先,我们需要了解如何将所有的iptables的INPUT链数据包记录到/var/log/messages中。如果你已经有一些iptables规则了,那么将记录日志...

如何安全管理SSH密钥以防止服务器被入侵

SSH密钥安全管理实施指南(2025年更新版)一、密钥生成与存储规范高强度密钥生成bashCopyCodessh-keygen-ted25519-a100#生成ED25519算法密钥(比...

在CentOS上安装nginx服务器(centos搭建代理服务器)

一、环境描述1.虚拟机配置CPU:单核内存:2GB硬盘:120GBIP:10.24.17.1082.操作系统版本:CentOS6.6x86_64安装方式:Minimal3.虚拟化环境VM...

CentOS7安全加固的一份整理规划建议

◆更新系统:及时更新CentOS7操作系统版本和安全补丁,确保系统以最新状态运行。◆关闭不必要的服务:在运行系统时,应关闭不需要的服务和端口,以减少系统暴露的攻击面。◆安装防火墙:使用iptables...

第四十七天-二叉树,centOS安装tomcat,Maven,vsftpd

学习笔记:1.Maven是Apache下的一个纯Java开发的开源项目。基于项目对象模型(缩写:POM)概念,Maven利用一个中央信息片断能管理一个项目的构建、报告和文档等步骤。Maven...

Linux远程桌面连接使用教程 Widows终端远程连接Linux服务器

一、前言为什么不是远程连接Linux服务器?因为我不会,远程连接window我就用电脑自带的“远程桌面连接”。以下所述都是在CentOS操作系统下的。服务器刚换成Linux的时候很迷茫,感觉无从下手...

CentOS 安全加固操作,保护你的操作系统

系统加固是保障系统安全的重要手段,对于维护企业数据安全、用户隐私以及系统稳定运行具有重要意义。加固后的系统更加健壮和稳定,能够有效减少因安全问题导致的系统故障和停机时间,提高系统的可用性和可靠性。通过...

Dockerfile部署Java项目(docker如何部署java项目)

1、概述本文主要会简单介绍什么是Docker,什么是Dockerfile,如何安装Docker,Dockerfile如何编写,如何通过Dockerfile安装jar包并外置yaml文件以及如何通过do...

CentOS7云主机部署Fail2ban阻断SSH暴力破解

关于Fail2banFail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽)例如:当有人在试探你的HTTP、SSH、SMTP、FTP密...

在CentOS7上用源码编译安装PostgreSQL

1、新建postgres用户#useraddpostgres&&passwdpostgres2、安装依赖包#yum-yinstallmakegccgcc-c++readline...

pure-ftpd 使用(ftp prompt命令)

pure-ftpd是一个免费的ftp软件,其他介绍就不多说了。我们直接开始主题安装centosyuminstallepel-releaseyuminstallpure-ftpd配置备份原配置...

取消回复欢迎 发表评论: