一条命令关掉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的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
随机推荐
- word模板导出的几种方式:第三种:标签替换(DocX组件读取与写入Word)
dll文件下载地址:https://files-cdn.cnblogs.com/files/daizhipeng/DocX.rar DocX wordDocumentOld = DocX.Load(S ...
- asp.net 对象转XML,XML转对象
//对象转XML public static string ObjToXml(object obj) { using (MemoryStream Stream = new MemoryStream() ...
- 打包加载 AssetBundle
1.先创建Asset序列化(单个文件夹所在文件夹路径,会遍历这个文件夹所有的Prefab,所有的Prefab名字不能重复,必须保证名字得唯一性),配置好ConfigAB表 /* ######### # ...
- 给GRUB添加新的项目
安装了win10,然后又安装了manjaro,最后又安装了Ubuntu.开机默认就是进入的Ubuntu的grub,然而我比较喜欢manjaro的grub主题.在bios中设置manjaro的引导为默认 ...
- jQuery_$方法、属性、点击切换
jQuery_$方法 1.$.each():遍历数组或对象中的数据 2.$.trim():去除字符串两边的空格 3.$.type(obj):得到数据的类型 4.$.isArray(obj):判断是否为 ...
- Windows server 2012 install .net core sdk 2.2.103
Windows8.1-KB2919442-x64 Windows8.1-KB2919355-x64 vc_redist.x64 dotnet-sdk-2.2.103-win-x64 dotnet-ho ...
- dao层、service和action的运用和区别
DAO层叫数据访问层,全称为data access object,属于一种比较底层,比较基础的操作,对于数据库的操作,具体到对于某个表的增删改查, 也就是说某个DAO一定是和数据库的某一张表一一对应的 ...
- 支付宝支付之App支付
与微信支付对比,支付宝支付就没有那么多坑了,毕竟支付宝开放平台的文档还是描述的很详细的. 支付宝开放平台地址:https://docs.open.alipay.com/204/105297/ 支付宝支 ...
- vue的一些随记
1.vue中在methods等中使用filters中的过滤器 this.$options.filters[filter](...args)
- 【书】.NET及计算机类相关书籍,持续更新...
一级目录 链接: https://pan.baidu.com/s/1y3osr3YCQ7XlM81RzkN1eQ 提取码: gs3r 二级目录 链接: https://pan.baidu.com/s/ ...