一条命令关掉centos所有不必要的服务和端口号
centos作为服务器开放的服务多了,难免一些服务软件有漏洞,开放的端口号越多,上线的服务器越危险,所以我们必须在服务器上线之前把centos里面不必要的服务全部干掉,不让坏人有可乘之机。
首先看一下机器里面运行了哪些服务:(我的机器运行级别是3,只看3:on的服务就可以了)
[root@centos ~]# chkconfig --list | grep "3:on"
NetworkManager :off :off :on :on :on :on :off
abrt-ccpp :off :off :on :on :on :on :off
abrtd :off :off :on :on :on :on :off
acpid :off :off :on :on :on :on :off
atd :off :off :on :on :on :on :off
auditd :off :off :on :on :on :on :off
autofs :off :off :on :on :on :on :off
blk-availability :off :on :on :on :on :on :off
certmonger :off :off :on :on :on :on :off
cgconfig :off :off :on :on :on :on :off
cgred :off :off :on :on :on :on :off
cpuspeed :off :on :on :on :on :on :off
crond :off :off :on :on :on :on :off
cups :off :off :on :on :on :on :off
dnsmasq :off :off :on :on :on :on :off
haldaemon :off :off :on :on :on :on :off
ip6tables :off :off :on :on :on :on :off
ipsec :off :off :on :on :on :on :off
iptables :off :off :on :on :on :on :off
irqbalance :off :off :on :on :on :on :off
kdump :off :off :on :on :on :on :off
lvm2-monitor :off :on :on :on :on :on :off
mcelogd :off :off :on :on :on :on :off
mdmonitor :off :off :on :on :on :on :off
messagebus :off :off :on :on :on :on :off
netconsole :off :off :on :on :on :on :off
netfs :off :off :on :on :on :on :off
network :off :off :on :on :on :on :off
nfs :off :off :on :on :on :on :off
nfslock :off :off :on :on :on :on :off
ntpd :off :off :on :on :on :on :off
ntpdate :off :off :on :on :on :on :off
numad :off :off :on :on :on :on :off
oddjobd :off :off :on :on :on :on :off
portreserve :off :off :on :on :on :on :off
postfix :off :off :on :on :on :on :off
pppoe-server :off :off :on :on :on :on :off
psacct :off :off :on :on :on :on :off
quota_nld :off :off :on :on :on :on :off
rdisc :off :off :on :on :on :on :off
restorecond :off :off :on :on :on :on :off
rngd :off :off :on :on :on :on :off
rpcbind :off :off :on :on :on :on :off
rpcgssd :off :off :on :on :on :on :off
rpcsvcgssd :off :off :on :on :on :on :off
rsyslog :off :off :on :on :on :on :off
saslauthd :off :off :on :on :on :on :off
smartd :off :off :on :on :on :on :off
sshd :off :off :on :on :on :on :off
sssd :off :off :on :on :on :on :off
svnserve :off :off :on :on :on :on :off
sysstat :off :on :on :on :on :on :off
udev-post :off :on :on :on :on :on :off
winbind :off :off :on :on :on :on :off
wpa_supplicant :off :off :on :on :on :on :off
ypbind :off :off :on :on :on :on :off
开的服务这么多,这要是直接放到互联网怎么了得,所以我们第一步先把所有的服务统统关掉,第二步再把要必须保留的服务开启。
第一步,关掉系统所有的服务,这么多内容只能用循环脚本了,一条一条chkconfig service off 猴年马月去了,直接看命令:
我把所有开着的服务名称 通过awk取出来,再用for循环 chkconfig service off
[root@centos ~]# for n in `chkconfig --list | grep "3:on" | awk '{print $1}'`;do chkconfig $n off;done
[root@centos ~]# chkconfig --list | grep :on
[root@centos ~]#
[root@centos ~]#
[root@centos ~]# //这会儿发现服务都被我一下子kill掉了
这会儿问题来了,我们的服务器哪些服务必须保留呢?
- network提供网络的服务,服务器不上网怎么能行呢?
- crond时间计划任务服务,服务器日常的计划执行离不开这个服务
- sshd 我们需要通过ssh 才能远程连接到我们的Linux,总不能天天在idc机房拿kvm来工作吧
- rsyslog 服务器做了哪些事情都需要靠日志才能知道,rsyslog就是用来记录日志的,原来名字叫syslog
- sysstat 监控系统性能的服务,对服务器掌控怎么能离得了它,sar,mpstat,iostat,vmstat都是非常有用的工具,都在这个服务里面
总结一下,系统必须开启的服务有network,sshd,crond,rsyslog,sysstat五个
我们要做的是开启这些服务,然后验证收工,go...
[root@centos ~]# for n in crond sshd network rsyslog sysstat ;do chkconfig $n on ; done
[root@centos ~]# chkconfig --list | grep :on
crond :off :off :on :on :on :on :off
network :off :off :on :on :on :on :off
rsyslog :off :off :on :on :on :on :off
sshd :off :off :on :on :on :on :off
sysstat :off :on :on :on :on :on :off
另外一种思路:我把该留下的留下,其他全部干掉
直接给答案:
[root@centos ~]# chkconfig --list | grep :on | egrep -v "sshd|network|rsyslog|sysstat|crond" | awk '{print "chkconfig",$1,"off"}'
chkconfig NetworkManager off
chkconfig abrt-ccpp off
chkconfig abrtd off
chkconfig acpid off
chkconfig atd off
chkconfig auditd off
chkconfig autofs off
chkconfig blk-availability off
chkconfig certmonger off
chkconfig cgconfig off
chkconfig cgred off
chkconfig cpuspeed off
chkconfig cups off
chkconfig dnsmasq off
chkconfig haldaemon off
chkconfig ip6tables off
chkconfig ipsec off
chkconfig iptables off
chkconfig irqbalance off
chkconfig kdump off
chkconfig lvm2-monitor off
chkconfig mcelogd off
chkconfig mdmonitor off
chkconfig messagebus off
chkconfig netconsole off
chkconfig netfs off
chkconfig nfs off
chkconfig nfslock off
chkconfig ntpd off
chkconfig ntpdate off
chkconfig numad off
chkconfig oddjobd off
chkconfig portreserve off
chkconfig postfix off
chkconfig pppoe-server off
chkconfig psacct off
chkconfig quota_nld off
chkconfig rdisc off
chkconfig restorecond off
chkconfig rngd off
chkconfig rpcbind off
chkconfig rpcgssd off
chkconfig rpcsvcgssd off
chkconfig saslauthd off
chkconfig smartd off
chkconfig sssd off
chkconfig svnserve off
chkconfig udev-post off
chkconfig winbind off
chkconfig wpa_supplicant off
chkconfig ypbind off
[root@centos ~]# chkconfig --list | grep 3:on | egrep -v "sshd|network|rsyslog|sysstat|crond" | awk '{print "chkconfig",$1,"off"}' | bash
一条命令关掉centos所有不必要的服务和端口号的更多相关文章
- CentOS 7.0 更改SSH 远程连接 端口号
许多学习过redhat 7的同学们,在使用centos的时候总会遇到一些问题,因为centos在安装时会默认开启一些服务,今天我们就来更改下centos 7.0的SSH端口. 操作步骤: 远程登录到c ...
- CentOS下常用的 19 条命令
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
- centos使用上一条命令的快捷键
使用上一条的最后一个参数 有时需要连续多个命令操作一个路径很长的文件: cat /usr/share/doc/centos-release/GPL 下一个命令可能还要使用这个路径,即使有命令补全也会很 ...
- 版本控制-svn服务器搭建和常用命令(centos 6.3)
Svn是比较优秀的版本控制工具,虽然功能和性能上无法和Git媲美,但由于其容易搭建和使用的特性,所以在各个小公司还是很受欢迎的.使用Git可参考<版本控制-Git服务器搭建和常用命令使用> ...
- 版本控制-https svn服务器搭建和常用命令(centos 6.3)
Svn是比较优秀的版本控制工具,虽然功能和性能上无法和Git媲美,但由于其容易搭建和使用的特性,所以在各个小公司还是很受欢迎的.使用Git可参考<版本控制-Git服务器搭建和常用命令使用> ...
- linux常用60条命令 转
Linux必学的60个命令 Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命 ...
- https://www.jqhtml.com/30047.html strace + 命令: 这条命令十分强大,可以定位你程序到底是哪个地方出了问题
https://www.jqhtml.com/30047.html 我的Linux手册 服务器 浏览数:72 2019-1-30 原文链接 基础安装 # CentOS sudo yum install ...
- 初窥Linux 之 我最常用的20条命令
魏公 SecureCRTuname -avisftppartition,fsshell kshell,bshelluser,groupIPTables文件数,内核参数tail,less/var/log ...
- linux最常用的20条命令
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
随机推荐
- SAP如何修改表的数据
修改表: 事务代码:se16n 输入表名字 输入 /h 进入维护模式 修改 GD-EDIT 和 GD-SAPEDIT 内容为大写X. se ...
- Session &cookie introduction,usage
Cookie 1)什么是Cookie? 服务器为了识别用户身份而临时存放在浏览器端的少量数据. 2)工作原理 浏览器访问服务器时,服务器将一些数据以set-cooki ...
- Oracle使用——数据泵导入导出数据库——impdp/expdp使用
使用前提 EXPDP和IMPDP只可以在Oracle服务端使用. EXP导出的文件只可以使用IMP导入,不适用于IMPDP导入文件:EXPDP导出的文件只可以使用IMPDP导入,而不适用于IMP导出文 ...
- SonarQube安装文档
1.SonarQube 1.1 SonarQube介绍 SonarQube是管理代码质量一个开放平台,可以快速的定位代码中潜在的或者明显的错误. SonarQube是否可以使用自定义规则由开发人员的开 ...
- LintCode 1.A+B的问题
LintCode 1.A+B的问题 描述 给出两个整数 a 和 b , 求他们的和. 答案 public class Solution { /** * @param a: An integer * @ ...
- 【python3】 函数 装饰器
第一步 : 了解装饰器 装饰器模式,重点在于装饰,装饰的核心仍是被装饰的对象. 举一个栗子:我今天穿了一件短袖,但是突然一阵风,短袖没办法为我御寒,我想到的办法是将短袖变得更厚更长,但是改造之后,它就 ...
- _spellmod_base
技能基础修改(进去可能会改动) 可以配合数据库的spell_dbc在线制作无补丁技能. 具体效果查询DBC表 `spellid` int(11) NOT NULL DEFAULT '0', `Effe ...
- CSS实现水平垂直居中的1010种方式
转载自:CSS实现水平垂直居中的1010种方式 划重点,这是一道面试必考题,很多面试官都喜欢问这个问题,我就被问过好几次了 要实现上图的效果看似很简单,实则暗藏玄机,本文总结了一下CSS实现水平垂直居 ...
- day23
## 复习 4.类与对象的语法class 类名: 代码块(一堆属性与方法)对象名 = 类名() 变量 | 函数 => 属性 | 方法:前者直接使用,通过所属者.语法调用 类会随所属文件加载而加载 ...
- 简单谈谈$.merge()
var arr1 = [1,2,3]; var arr2 = [1,2,3]; console.log($.merge(arr1,arr2)) //[1,2,3,1,2,3],可见数组间只是合并,不会 ...