RHEL8系统基础优化
配置主机名
# 配置主机名
hostnamectl set-hostname el8
配置locale.conf
vi /etc/locale.conf
配置内容如下
# 覆盖系统所有语言设置
LC_ALL=zh_CN.UTF-8
# 设置默认语言
LANG=zh_CN.uft8
配置yum国内源
参考: https://gitcode.com/liqiaofei/centos7_yum_repo
# 备份yum源
mv /etc/yum.repos.d{,.bak} && mkdir -p /etc/yum.repos.d && cd /etc/yum.repos.d
# 下载CentOS-Base.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/CentOS-Base.repo
# 下载elrepo.repo
curl -o /etc/yum.repos.d/elrepo.repo https://raw.gitcode.com/liqiaofei/centos7_yum_repo/raw/main/el8-el9/elrepo.repo
# 下载epel.repo
curl -o /etc/yum.repos.d/epel.repo https://raw.gitcode.com/liqiaofei/centos7_yum_repo/raw/main/el8-el9/epel.repo
# 下载CentOS-SCLo-scl-rh.repo
curl -o /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/CentOS-SCLo-scl-rh.repo
# 下载CentOS-SCLo-scl.repo
curl -o /etc/yum.repos.d/CentOS-SCLo-scl.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/CentOS-SCLo-scl.repo
# 下载ius.repo
curl -o /etc/yum.repos.d/ius.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/ius.repo
安装常用软件
# 安装dnf插件
dnf install -y dnf-utils dnf-plugin-versionlock
# 安装常用软件
dnf install -y bash-completion mlocate rsync vim wget net-tools
关闭防火墙和SELinux
# 关闭防火墙
systemctl disable --now firewalld
# 关闭selinux
sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config
# 临时关闭SELinux
setenforce 0
性能调优
- 配置tuned自动性能调优
- 关闭不必要服务
美化系统
vim美化
# 下载vim配置文件
wget -cP $HOME/ https://raw.gitcode.com/liqiaofei/vim-config/raw/main/.vimrc
美化cat
美化ps1
# 下载ps1优化配置文件
wget -cP /etc/profile.d https://raw.gitcode.com/liqiaofei/profile.d/raw/main/ps1.sh
配置git命令自动补全
# 下载git-completion.sh
wget -cP /etc/profile.d/ https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
配置系统欢迎语
/etc/issue
和 /etc/motd
区别
特性 | /etc/issue | /etc/motd (Message Of The Day) |
---|---|---|
显示时机 | 登录前 (在登录提示符上方显示) | 登录后 (用户成功登录后显示) |
主要用途 | 显示系统标识、警告或登录前的法律声明 | 显示动态系统消息、维护通知或欢迎信息 |
内容更新 | 通常为静态文本 | 支持动态生成(通过脚本或 /etc/motd.d/ >) |
典型应用场景 | 法律声明、SSH登录前的安全警告 | 系统状态、维护通知、每日提示 |
修改方式 | 直接编辑文件 | 可编辑文件或通过 /etc/motd.d/ 分片管理 |
配置/etc/issue.net登陆前
欢迎语
tee /etc/issue.net <<-'EOF'
【法律警告】
本系统仅供授权人员访问。所有登录尝试和系统内的操作行为都将被实时监控、记录和审计。未经授权的访问、使用、修改或传播系统信息属于非法行为,将承担严厉的法律责任,包括但不限于民事赔偿、行政处罚乃至刑事起诉。继续登录表示您已阅读、理解并同意接受上述条款和相关信息安全策略的约束。
EOF
修改sshd配置
# 使用sed命令修改SSH配置文件中的Banner设置(需管理员权限)
# sed -i:直接修改目标文件(不生成备份)
# - 's/^#\s*Banner\s*none/Banner \/etc\/issue.net/g':正则表达式替换规则
# 分解:
# ^#\s* : 匹配以#开头且后面有任意空格的注释行
# Banner\s* : 匹配Banner关键字及后面任意空格
# none : 匹配原始配置的"none"参数
# Banner \/etc\/issue.net : 替换为指定路径的banner文件(转义斜杠)
# g : 全局替换(防止重复配置项)
# - /etc/ssh/sshd_config:SSH服务主配置文件路径
sudo sed -i 's/^#\s*Banner\s*none/Banner \/etc\/issue.net/g' /etc/ssh/sshd_config
查看Banner
配置
grep Banner /etc/ssh/sshd_config
# 重启sshd服务
systemctl restart sshd
配置/etc/motd登陆后
欢迎语
tee /etc/motd.d/00-welcome <<-'EOF'
【法律警告】
本系统仅供授权人员访问。所有登录尝试和系统内的操作行为都将被实时监控、记录和审计。未经授权的访问、使用、修改或传播系统信息属于非法行为,将承担严厉的法律责任,包括但不限于民事赔偿、行政处罚乃至刑事起诉。继续登录表示您已阅读、理解并同意接受上述条款和相关信息安全策略的约束。
EOF
安全配置
使用fail2ban防止ssh穷举爆破 :
配置ipset
配置IP白名单
和IP黑名单
https://blog.csdn.net/omaidb/article/details/120405741