First, system security 1. User Management(1) Delete users who are not in use for a long time
userdel [-r] 用户名
Options
-r:删除指定用户家目录
(2) Set Program user Shell to not allow login system
usermod -s /sbin/nologin 用户
(3) Temporary use of the user (set maximum user lifetime)
chage -E "时间" 用户 //设置账号失效时间chage -l 用户 //查看账号的密码控制信息(如最短、最长密码使用时间等)
(4) Lock the file, the file cannot be deleted (sticky bit)
① for file sticky bits, root users are also restricted
chattr +i /etc/passwd && chattr +i /etc/shadow //指定文件将不能删除chattr -i /etc/passwd && chattr -i /etc/shadow //移除指定文件的粘滞位lsattr <文件> //查看指定用户是否设置粘滞位
② file or directory sticky bits, owner and root user unrestricted
chmod o+t <目录/文件> //给指定目录/文件设置粘滞位chmod o-t <目录/文件> //给指定目录/文件取消粘滞位ls -ld <目录> //查看目录的粘滞位设置情况(t权限位)
(5) Set Password expiration date
User already exists
passwd -S 用户 //查看用户密码状态passwd -x 天数 用户 //设置密码的有效期
The new user
vim /etc/login.defs //更改默认新建用户参数的文件PASS_MAX_DAYS 天数
2.Linux Privileged Permissions
作用 SUID:对二进制文件生效,使普通用户以所有者的权限执行文件 SGID:对目录生效,保持原目录的所有组 Stickybit:防止用户删除文件/目录,针对其他用户设置,root用户无效格式 SUID:[chmod u+s | u-s] 文件 SGID:[chmod g+s | g-s] 目录 Stickybit(粘滞位):chmod [o+t | o-t] 文件/目录八进制:SUID=4、SGID=2、Stickybit=1
Cases:
chmod u+s /tmp/2333.txtThe settings file has suid (the user has the owner's permission to execute the file)
chmod g+s /tmp/2333.txtThe settings file has Sgid (users have permission to execute the file with a group)
chmod 4755 文件/目录Set the file or directory to have suid and owner full permissions, all groups have read, execute permissions, other users have read, execute permissions
Second, Su, sudo 1.SU: Toggle the specified user
Grammar
su [-] 用户
VIM/ETC/PAM.D/SU//Modify PAM configuration file
auth required pam_wheel.so use_uid //PAM模块认证,只有属于wheel组用户可切换到root
View the Security authentication log file
tail -f /var/log/secure
Note : need to cooperate with remote control, set the root user to prohibit remote login
2.sudo: Temporary power, ordinary users to temporarily execute the command as root
vim /etc/sudoers或visudo //编辑sudo配置文件,默认不能直接使用[用户名] [主机] [命令]
Note : commands are preferable to reverse, such as!/bin/(means except for/bin/directories)
Cases:
U01 all= (All) all//Allow u01 users to use sudo to execute all commands as root
U01 all= (All) all,!/sbin/reboot//Allow u01 users to use sudo to execute all commands in root, except/sbin/reboot
(1) alias set in file
Cmnd_Alias 别名(大写)=命令 //定义命令别名User_Alias 别名(大写)=用户名 //定义用户别名Host_Alias 别名(大写)=网段,IP地址 //定义主机别名
Cases:
Cmnd_alias cmd=all,!/sbin/reboot//define command aliases, Cmd=all,!/sbin/reboot
User_alias user=u01,u02//define user aliases, user=u01,u02
Host_alias host=192.168.10.44//define host alias, host=192.168.10.44
User Host=cmd//Allow user aliases (U01, u02 users) to execute a CMD alias (All,!/sbin/reboot) in the HOST alias (192.168.10.44)
(2) Logging
vim /etc/sudoers //修改sudo配置文件Defaults logfile=/var/log/sudo //定义日志记录并指定存储位置tail -f /var/log/sudo //动态查看sudo日志文件sudo -l //查看当前用户所有sudo能执行的命令
Note: The default user will retain 5 minutes after using sudo, and in 5 minutes the user will not need to enter the current user password again.
Third, System Management 1. Automatically empty history commands
vim ~/.bashrc //用户登陆时自动清空历史命令 echo "" >~/.bash_history
history -c //清楚当前用户登陆终端历史命令(再次登陆依然存在)
vim /etc/profile HISTSIZE=0 //更改历史命令记录数量
2. Automatic logoff after the terminal has exceeded idle time
vim /etc/profile //全局变量定义文件(所有用户生效) TMOUT=秒数 //指定终端超时时间
vim ~/.bash_profile //只对当前用户生效 TMOUT=秒数 //指定终端超时时间
Iv. safety control of Switch machine 1. Disable the Ctrl-alt-delete hotkey
vim /etc/init/control-alt-delete.conf注释掉最后一行(加#)
2.GRUB Menu RestrictionsPlainText Password
vim /boot/grub/grub.conf password 密码 //title之前
Ciphertext Password
grub-md5-crypt //将输入的字符串使用md5方式转换vim /boot/grub/grub.conf password --md5 加密字符串 //title之前
3. Reduce the number of TTY terminals
vim /etc/sysconfig/init ACTION_CONSOLES=/dev/tty[1-6] //改动tty[1-6]数值可实现控制
Cases:
Action_consoles=/dev/tty[1-3]//Open tty1, Tty2, Tty3
action_consoles=/dev/tty[1,3,6]//Open tty1, Tty3, Tty6
ACTION_CONSOLES=/DEV/TTY[1-1,3-3,6-6]//Open tty1, Tty3, Tty6
4. Prohibit normal User Login
touch /etc/nologin //新建文件nologin,所有用户无法登陆(除root)rm -rf /etc/nologin //解锁,普通可登录
5. Scanning
Grammar
nmap -A -O -PO -vv 网段/IP/域名 //扫描指定主机的OS、端口、MAC等信息
Recommended Scan Type
-PO:主机禁止ping时,可强制扫描-sU:扫描UDP-sT:扫描TCP-p:扫描指定端口
Linux system security