3

Linux系统笔记大杂烩

 1 year ago
source link: https://blog.51cto.com/lidabai/5370164
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux系统笔记大杂烩

原创

键客李大白 2022-06-09 12:52:16 博主文章分类:李大白的运维笔记 ©著作权

文章标签 linux 重启 数据 文章分类 Linux 系统/运维 阅读数196

Linux优化与加固

  • 历史记录数量与登录超时,环境变量设置
  • 隐藏 Linux版本信息
  • Linux 服务器内核参数优化
  • 定时清理垃圾邮件 & 小文件
  • 锁定关键系统文件,防止被提权篡改
  • 给 grub菜单加密码
  • 禁止 Linux系统被ping

隐藏 Linux版本信息

​ 在登录Linux主机本地(非CRT连接)前,会显示系统的版本和内核。为了安全我们应该隐藏它。

方式一、编辑/etc/motd文件,来隐藏真正的版本信息。

/etc/motd即messageoftoday(布告栏信息)。

每次用户登录时,/etc/motd文件的内容会显示在用户的终端。系统管理员可以在文件中编辑系统活动消息。

方式二、

登录信息显示数据 : /etc/issue (无论登录成功与否都会显示)

清空的命令

# > /etc/issue 或 cat /dev/null >etc/issue
# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
# >/etc/issue #清空/etc/issue

 ​https://edu.51cto.com/course/24429.html​​ 查询内存最高的命令

ps aux |head -1 ; ps aux|sort -k4rn |head -10

查询cpu最高的命令

ps aux |head -1 ; ps aux|sort -k3rn |head -10


1、重置root密码

​ 前提:必须是服务器的管理者,有其他可用账户。

步骤如下:

1)重启系统,进入恢复模式(recovery)

按e键找到linux16该行,在行末空格输入

rd.break console=tty0 ctrl + x 启动,会看到switch_root#

2)以可写方式重新挂载 /,并切换到此环境

sh-4.4# mount -o remount,rw /sysroot #让根目录下所有数据,可读可写
root# chroot /sysroot #切换到硬盘操作系统的环境

3)重新设置root的密码

sh-4.4# echo 密码 | passwd --stdin root

4)如果SELinux是强制模式,才需要重设SELinux策略(其他模式不需要做此操作)

sh-4.4# cat /etc/selinux/config #查看SELinux开机的运行模式
sh-4.4# touch /.autorelabel #SELinux是强制模式,让SELinux失忆

5)强制重启系统完成修复:

sh-4.4# reboot -f

2、取消tab键滴滴的声音

# vim /etc/inputrc
set bell-style none #去掉前面的注释
# sed -i '/none/s/#set/set/' /etc/inputrc #也可通过该方式修改
# vim /etc/bashrc
1 setterm -blength 0 #设置终端属性
# reboot #重启生效

3、LInux中的”黑洞“

/dev/null 是一个特殊的设备文件,这个文件接收到任何数据都会被丢弃,俗称“黑洞”

使用技巧:

2>/dev/null 将错误的结果输出到“黑洞”,不会显示到终端

0 是标准输入,一般是从键盘获得输入

1 是标准输出,一般是输出到屏幕了

2 是标准错误,有时候屏幕上可以看到,但是重定向的文件中看不到的就是它了

4、开机自启服务

​ 在主机开机时,会加载/etc/rc.local(开机自动读取其中的配置)文件中的配置,可以将一些服务加到该文件中实现服务的开机自动启动。

使用:

# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local #设置nginx开机自动启动
# chmod +x /etc/rc.local #给该文件执行权限

5、设置个性登录提示

# vim /etc/bashrc #在顶部添加以下内容
c2="$(tput bold)$(tput setaf 2)"
echo "$c2 _ _ _ ___ "
echo "$c2 | | (_) | | / __)"
echo "$c2 | | _ _ ____ ____| | _____ _____ _| |__ "
echo "$c2 | |_/ ) |/ ___) ___) || ___ (____ (_ __)"
echo "$c2 | _ (| ( (__( (___| || ____/ ___ | | | "
echo "$c2 |_| \_)_|\____)____)\_)_____)_____| |_| "
echo "$(tput sgr0)"

/etc/issue 亦可

6、个性化终端颜色

  • 1
  • 1收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK