# 临时生效,5分钟自动退出exportTMOUT=300# 对所有用户生效# vim /etc/profileexportTMOUT=300# 避免 TMOUT 被其他人重写readonlyTMOUT
# 取消超时退出# vim /etc/profileexportTMOUT=0# 登录策略# vim /etc/login.defs# LOG_UNKFAIL_ENAB 当用户登录失败时,将用户名记录到日志# LOGIN_RETRIES 用户输入密码最大错误次数,超过则会报错退出,但是改值会被 pam_pwquality.so 模块的 retry=6 参数重写# LASTLOG_ENAB 开启登录日志记录功能,且会将登录时间信息记录到日志 /var/log/lastlogLOG_UNKFAIL_ENAByes
LOGIN_RETRIES6LASTLOG_ENAByes
# vim /etc/profile# 内存最大可保留历史命令条数exportHISTSIZE=1000# ~/.bash_history 最多可保留条数exportHISTFILESIZE=5000# 历史命令时间格式exportHISTTIMEFORMAT="`who am i |xargs -x echo` || "
安全设置
# 禁止通过 ctrl-alt-del 快捷键重启服务器# mask ctrl-alt-del.target unit (this in fact creates symlink to /dev/null)systemctlmaskctrl-alt-del.target
# 验证ls-l/etc/systemd/system/ctrl-alt-del.target
lrwxrwxrwx1rootroot9Mar2314:51/etc/systemd/system/ctrl-alt-del.target->/dev/null
# SSH 服务配置# vim sshd_config# 输入密码错误超过 3 次,则记录到日志里MaxAuthTries3# 允许用户使用密码登录,默认 yesPasswordAuthenticationyes
# Specifies whether rhosts or /etc/hosts.equiv authentication together with successful RSA host authentication is allowed. # The default is “no”. This option applies to protocol version 1 only.RhostsRSAAuthenticationno
# 不允许以空密码登录,默认 noPermitEmptyPasswordsno
# 严格模式 # Specifies whether sshd should check file modes and ownership of the user’s files and home directory before accepting login.# This is normally desirable because novices sometimes accidentally leave their directory or files world-writable. The default is “yes”.StrictModesyes# 日志记录级别# Gives the verbosity level that is used when logging messages from sshd. The possible values are: QUIET, FATAL, ERROR, INFO,# VERBOSE, DEBUG, DEBUG1, DEBUG2 and DEBUG3. The default is INFO.LogLevelINFO
# Specifies whether sshd should ignore the user’s ~/.ssh/known_hosts during RhostsRSAAuthentication or HostbasedAuthentication. The default is “no”.IgnoreUserKnownHostsyes
# 加密方式 + 号的方式在 RHEL7+、Kylin V7+ 版本支持Ciphers+3des-cbc
# Specifies the available MAC (message authentication code) algorithms.MACs+hmac-sha1,hmac-md5
# 禁止 usb 功能# vim /etc/modprobe.d/usb_storage.confinstallusb-storage/bin/true
# 重载配置rmmodusb-storage
# auditd 配置# vim /etc/audit/auditd.conf# 最大保留的日志文件数# This keyword specifies the number of log files to keep if rotate is given as the max_log_file_action.num_logs4# 单文件 50MB 后触发轮转# This keyword specifies the maximum file size in megabytes.max_log_file=50max_log_file_action=ROTATE
# 只特定用户从特定客户端登录# 首先在 ssh 启用 pam_access.so 验证# vim /etc/pam.d/sshdaccountrequiredpam_access.so
# grants the user bakroot access to all hosts except 10.0.0.2 and 10.0.0.3.# Here's a breakdown of the line:# - indicates that this is a deny rule. If the line started with a +, it would be a permit rule.# bakroot is the user that the rule applies to.# ALL is a keyword that means "all hosts".# EXCEPT is a keyword that means "except the following hosts".# 10.0.0.2 and 10.0.0.3 are the IP addresses of the hosts that the user bakroot should not have access to.# So, in summary, this rule denies access to the user bakroot for all hosts except 10.0.0.2 and 10.0.0.3.# vim /etc/security/access.conf-:bakroot:ALLEXCEPT10.0.0.210.0.0.3