账号和权限
系统用户
- 超级管理员:UID=0
- 系统默认用户:系统程序使用,从不登录
- 新增普通用户:UID大于500
用户管理
- 添加用户:useradd <用户名>
- 删除用户:userdel [-r] [-f] <用户名>
锁定/解锁用户:
用户属性:
- usermod -L <用户名> #锁定用户
- usermod -U <用户名> #解锁用户
查看当前用户
id
权限管理
解析文件权限
[root@anonymous ~]# ls -ld /etc/passwd /bootdr-xr-xr-x. 5 root root 4096 2月 2 08:49 /boot-rw-r--r-- 1 root root 1240 1月 27 08:18 /etc/passwd
-rw-r--r--:权限位 1:硬链接数root:属主root:属组1240:文件大小1月 27 08:18:最后修改时间/etc/passwd:文件/目录名称
权限和归属
访问权限:
- - 读取:允许查看内容read
- - 写入:允许修改内容write
- - 可执行:允许执行和切换excute
归属关系
- - 所有者:拥有此文件/目录的用户user
- - 所属组:拥有此文件/目录的组group
- - 其他用户:除所有者、所属组以外的用户other
- - 所有用户:以上三类归属合称all
文件系统安全
查看权限:ls -l
修改权限:
设置合理的初始文件权限
UMASK
umask值为0022所对应的默认文件和文件夹创建的缺省权限分别为644和755
文件夹其权限规则为:777-022-755
文件其权限规则为:777-111-022=644(因为文件默认没有执行权限)
修改UMASK值:
1、直接在命令行下 umask xxx(重启后消失)
2、修改/etc/profile中设定的umask值
[root@anonymous ~]# umask 027[root@anonymous ~]# touch test2[root@anonymous ~]# ls -l test2-rw-r----- 1 root root 0 2月 2 09:24 test2[root@anonymous ~]# mkdir test10[root@anonymous ~]# ls -ld test10drwxr-x--- 2 root root 6 2月 2 09:24 test10
系统加固
锁定系统中多余的自建账号
执行命令
- cat /etc/passwd
- cat /etc/shadow
查看账户、口令文件,与管理员确认不必要的账号。对于一些保留的系统伪账号,如bin、adm、uucp、ip、nuucp、hpdb、www、daemon等可根据需要锁定登录。
加固方法:
- passwd -l <用户名> #锁定用户
- passwd -u <用户名> #解锁用户
检查shadow中空口令账号
加固方法:
- 使用命令passwd -l <用户名> 锁定不必要的账号
- 使用命令passwd -u <用户名>解锁需要恢复的账号
- 使用命令passwd <用户名> 为用户设置密码
设置系统密码策略
执行命令查看密码策略设置
加固方法
禁用root之外的超级用户
加固方法:
passwd -l <用户名>
限制能够su为root的用户
查看是否有auth required /libsecurity/pam_whell.so这样的配置条目
加固方法:
重要文件加上不可改变属性
把重要文件加上不可改变属性
Umask安全
SSH安全:
禁止root用户进行远程登陆
检查方法:
屏蔽SSH登陆banner信息
仅允许SSH协议版本2
防止误使用Ctrl+Alt+Del重启系统
检查方法:
加固方法:
设置账号锁定登录失败锁定次数、锁定时间
修改账号TMOUT值,设置自动注销时间
检查方法:
cat /etc/profile | grep TMOUT
加固方法:
vim /etc/profile
增加
TMOUT=600 无操作600秒后自动退出
设置BASH保留历史命令的条目
检查方法:
cat /etc/profile | grep HISTSIZE加固方法:
vim /etc/profile
修改HISTSIZE=5即保留最新执行的5条命令
注销时删除命令记录
检查方法:
cat /etc/skel/.bash_logout 增加如下行
rm -f $HOME/.bash_history
这样,系统中的所有用户注销时都会删除其命令记录,如果只需要针对某个特定用户,,如root用户进行设置,则可只在该用户的主目录下修改/$HOME/.bash_history文件增加相同的一行即可。
设置系统日志策略配置文件
日志的主要用途是系统审计 、监测追踪和分析。为了保证 Linux 系统正常运行、准确解决遇到的各种各样的问题,认真地读取日志文件是管理员的一项非常重要任务。
UNIX/ Linux 采用了syslog 工具来实现此功能,如果配置正确的 话,所有在主机上发生的事情都会被记录下来不管是好还是坏的
检查方法:
cat /etc/profile | grep HISTSIZE
确定syslog服务是否启用
[root@anonymous ~]# cat /etc/rsyslog.conf# rsyslog configuration file# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html# or latest version online at http://www.rsyslog.com/doc/rsyslog_conf.html# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html#### MODULES ####module(load="imuxsock" # provides support for local system logging (e.g. via logger command) SysSock.Use="off") # Turn off message reception via local log socket; # local messages are retrieved through imjournal now.module(load="imjournal" # provides access to the systemd journal UsePid="system" # PID nummber is retrieved as the ID of the process the journal entry originates from StateFile="imjournal.state") # File to store the position in the journal#module(load="imklog") # reads kernel messages (the same are read from journald)#module(load="immark") # provides --MARK-- message capability# Provides UDP syslog reception# for parameters see http://www.rsyslog.com/doc/imudp.html#module(load="imudp") # needs to be done just once#input(type="imudp" port="514")# Provides TCP syslog reception# for parameters see http://www.rsyslog.com/doc/imtcp.html#module(load="imtcp") # needs to be done just once#input(type="imtcp" port="514")#### GLOBAL DIRECTIVES ##### Where to place auxiliary filesglobal(workDirectory="/var/lib/rsyslog")# Use default timestamp formatmodule(load="builtin:omfile" Template="RSYSLOG_TraditionalFileFormat")# Include all config files in /etc/rsyslog.d/include(file="/etc/rsyslog.d/*.conf" mode="optional")#### RULES ##### Log all kernel messages to the console.# Logging much else clutters up the screen.#kern.* /dev/console# Log anything (except mail) of level info or higher.# Don't log private authentication messages!*.info;mail.none;authpriv.none;cron.none /var/log/messages# The authpriv file has restricted access.authpriv.* /var/log/secure# Log all the mail messages in one place.mail.* -/var/log/maillog# Log cron stuffcron.* /var/log/cron# Everybody gets emergency messages*.emerg :omusrmsg:*# Save news errors of level crit and higher in a special file.uucp,news.crit /var/log/spooler# Save boot messages also to boot.loglocal7.* /var/log/boot.log# ### sample forwarding rule ####action(type="omfwd"# An on-disk queue is created for this action. If the remote host is# down, messages are spooled to disk and sent when it is up again.#queue.filename="fwdRule1" # unique name prefix for spool files#queue.maxdiskspace="1g" # 1gb space limit (use as much as possible)#queue.saveonshutdown="on" # save messages to disk on shutdown#queue.type="LinkedList" # run asynchronously#action.resumeRetryCount="-1" # infinite retries if host is down# Remote Logging (we use TCP for reliable delivery)# remote_host is: name/ip, e.g. 192.168.0.1, port optional e.g. 10514#Target="remote_host" Port="XXX" Protocol="tcp")
查看syslogd的配置,并确认日志文件是否存在
阻止系统响应任何从外部/内部来的ping请求
加固方法:
echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all
文章转自运维星火燎原
链接:https://www.cnblogs.com/cherishthepresent/p/18051295
(版权归原作者所有,侵删)
原文始发于微信公众号(网络安全资源库):Linux安全加固
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论