一条命令关掉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的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
随机推荐
- 【双目备课】《学习OpenCV第18章》相机模型与标定整编
一.相机模型 针孔模型.在这个简单模型中,想象光线是从场景或一个很远的物体发射过来的,但只有一条光线从该场景中的任意特定点进入针孔. 我们将这个图像进行抽象,就能够得到这样的结果: 其中,f为像到针孔 ...
- writeup
``` #签到题``` 请打开微信关注,发送give me flag,即可获得.```Encode````1.ACSCLL首先看到这类题,我们肯定是要使用ASCLL的(这么明显的提示大家肯定一眼就能看 ...
- 单元测试系列之十一:Jmockit之mock特性详解
本文是Jmockit学习过程中,根据官网所列的工具特性进行解读. 1.调用次数约束(Invocation count constraints) 可以通过调用计数约束来指定预期和/或允许匹配给定期望的调 ...
- myeclipse编码问题
在中文操作系统中,Eclipse中的Java类型文件的编码的默认设置是GBK, 但是对Properties资源文件的编码的默认设置是ISO-8859-1. 所以编辑Java文件中的中文不会出现问题,但 ...
- js可拖拽的div
function chatDrag(div1) { div1.onmousedown = function (ev) { var oevent = ev || event; var distanceX ...
- shell for 循环
test.sh #!/bin/bash for str in "C语言" "http://www.bilibili.com" "成立7年了" ...
- selenium+java二元素定位
页面元素定位是自动化中最重要的事情, selenium Webdriver 提供了很多种元素定位的方法. 测试人员应该熟练掌握各种定位方法. 使用最简单,最稳定的定位方法. 自动化测试步骤 定位元素 ...
- c#领域驱动设计
代码是个程序员都能写, 怎么的代码才是好的, --------------------------------------------------------------------------- ...
- Cocos Creator学习六:加载/释放图片资源
1.目的:学习加载图片资源.使用图片资源创建对象以及释放图片资源. 2.注意事项以及主要函数: ①注意事项:使用loadRes函数,资源必须放置在assets下的resources文件夹下(默认没有r ...
- vue history模式
注意: 1.前端:config.js路径问题 2.后台:配置nginx