# You a small partner Hello everyone, this is to share relevant theoretical knowledge and system security applications and operating system Linux. I will be illustrated by the following analysis and related experiments:
A clean-up system accounts:
- The non-logged-in user's shell to / sbin / nologin
- Long-term use of the account is not locked
- Delete unused accounts
- Lock the account file passwd, shadow
Next we do the experiment for control and management account file:
Enter: grep "bash" $ "/ etc / passwd ( see which users can log in the current server)
Input: useradd lisi (add user lisi)
enter: passwd lisi (to lisi account password)
enter: grep" bash "$" / etc / passwd (now appears with a root, zhngsan, lisi three account can log)
file locking steps:
input: lssttr / etc / passwd / etc / shadow ( see the case file unlocked state)
input: chattr + i / etc / passwd / etc / shadow ( the file lock)
input: lssttr / etc / passwd / etc / shadow ( see the case file status is locked, there are "i" symbol)
input: useradd wangwu (this time can not add user)
input: chattr -i / etc / passwd / etc / shadow ( the account unlock the file)
over the implementation process is as follows:
Second, password security control:
1. Set password expiration
Change Password 2. When the user next logs required
常用格式:
[root@localhost~]#vi /etc/login.defs(适用于新建用户)
……
PASS_MAX_DAYS 30
[root@localhost~]#chage -M 30 lisi(适用于已由用户)
[root@localhost~]#chage-d 0 zhngsan(强制在下次登录时更改密码)
设置密码有效期的实验:
输入:vim /etc/shadow(查看账户密码文件)
输入:q(退出)
输入:vim /etc/login.defs(改密码属性文件)
输入:/99999(定位查询)
按:dw(删除当前数值)
按:a(插入)
输入:30(设置新的数值)
输入:wq(保存退出)
创建新用户验证:
输入:useradd zhaoliu(创建新用户zhaoliu)
输入:passwd zhaoliu(设置密码,此处123123)
输入:vim /etc/shadow(再次查看账户密码文件)
此时发现对比:新创建zhaoliu用户有效期为30天,而老用户不生效依然为99999天
以上过程执行如下:
接下来就是解决已创建用户密码最长时间的修改问题:
输入:chage -M 30 wangwu (修改已由账户wangwu的密码失效最长时间为30天)
输入:vim /etc/shadow(查看账户密码文件)
此时发现wangwu账户密码最长失效时间被修改为30天
以上过程执行如下:
设置下一次登录时需要修改密码实验:
1、输入:chage -d 0 lisi(设置李四下次登录时需要重新设置密码)
2、输入:vim /etc/shadow(查看账户密码文件查看lisi账户的密码有效期)
3、此时还是99999,没有变化
我们进入CentOS 7本地终端使用lisi账户进行登录:
4、lisi账户,输入原有密码123123回车登录
5、此时提示输入UNIX密码,依然输入lisi账户之前的密码123123回车登录
6、接下来提示我们设置新密码,输入:321abc!回车后提示“密码未通过字典检查,过于简单”
7、此处经过多次测试,输入如下密码:asdf1928,回车可进入下一步确认密码界面,输入相同密码后就可进入系统
以上过程执行如下:
博主亲测提示:此处修改的密码不允许用连续的字母和阿拉伯数字,否则强行尝试会让你怀疑人生!
三.命令历史限制
1.减少记录的命令条数(原本有1000条)
2.注销时自动清空命令历史
常见选项示例:
[root@localhost~]#vi/etc/profile
HISTSIZE=200
[root@localhost~]#vi ~/.bash_logout
history -c
clear
命令历史限制实验:
输入:history(查看历史命令记录)
在此处可以产看到默认的留存历史命令记录为1000条
输入:/1000,查找到此处
按:Shift+R,替换
输入:20,光标移到后面两个0,按x删除
输入:wq保存退出
输入:history(再次查看历史命令记录)
此时依然显示我们之前所有命令的总条数,而不是20条,是因为我们在更改过配置之后需要让它生效之后再重新查看才可以
输入:source /etc/prfile(修改配置生效)
输入:history(再次查看历史命令记录)
此时显示出来的就是我们输入的最后20条历史命令
以上过程执行结果如下:
如果只想针对用户进行注销时自动清空命令历史的话,该如何操作:
此处例如lisi账户
输入:cd /home/lisi(进入lisi账户的家目录)
输入:ls -a(查看隐藏文件)
执行:.bash_profile(客户环境变量文件)
输入:vim .bash_logout(对登出的变量文件进行编辑)
输入:history -c(清空历史)
输入:clear(清空缓存)
输入:wq(保存退出)
以上过程执行过程结果如下:
四.终端自动注销:
1.闲置600秒后自动注销
示例:br/>[root@localhost~]#vi~/.bash_profile
export TMOUT=600
设置终端自动注销实验:
Input: vim / etc / profile (specified)
by: Big G to the last line
by: O (Inserts)
Input: export TMOUT = 15 (set to automatically logoff 15S)
Input: WQ (save and exit)
Input: source / etc / profile (modified execution)
wait 15 seconds you will be prompted to enter the wait timeout, automatically logout
the above execution results are as follows: