centos 5.1下的安全設(shè)置(適合所有的linux版本)
更新時(shí)間:2010年03月11日 21:59:04 作者:
因?yàn)閞oot用戶對系統(tǒng)具有全權(quán)的操作權(quán)限,為了避免一些失誤的操作,建議在一般情況下,以一般用戶登錄系統(tǒng),必要的時(shí)候需要root操作權(quán)限時(shí),再通過“su -”命令來登錄為root用戶進(jìn)行操作。
在 一般情況下,一般用戶通過執(zhí)行“su -”命令、輸入正確的root密碼,可以登錄為root用戶來對系統(tǒng)進(jìn)行管理員級別的配置。但是,為了更進(jìn)一步加強(qiáng)系統(tǒng)的安全性,有必要建立一個(gè)管理員的 組,只允許這個(gè)組的用戶來執(zhí)行“su -”命令登錄為root用戶,而讓其他組的用戶即使執(zhí)行“su -”、輸入了正確的root密碼,也無法登錄為root用戶。在UNIX下,這個(gè)組的名稱通常為“wheel”。
首先我們創(chuàng)建兩個(gè)普通的用戶tom john
[root@www ~]# useradd tom
[root@www ~]# passwd tom
輸入你的密碼
[root@www ~]# useradd john
[root@www ~]# passwd john
輸入你的密碼
[root@www ~]# usermod -g wheel tom 將tom用戶加入到wheel組中
[root@www ~]# vi /etc/pam.d/su ← 打開這個(gè)配置文件找到這句話在第六行將其前面的#注釋掉
# auth required pam_wheel.so use_uid
[root@www ~]# echo “SU_WHEEL_ONLY yes” >> /etc/login.defs
然后你可以分別用tom和john登陸,沒有加入到wheel組的用戶,執(zhí)行“su -”命令,即使輸入了正確的root密碼,也無法登錄為root用戶
在系統(tǒng)出現(xiàn)錯(cuò)誤或有重要通知發(fā)送郵件給root的時(shí)候,讓系統(tǒng)自動(dòng)轉(zhuǎn)送到我們通常使用的郵箱中,這樣方便查閱相關(guān)報(bào)告和日志。
[root@www ~]# vi /etc/aliases
在這兩句下面mailer-daemon: postmaster
postmaster: root
加入這句話root: zy66289214@126.com 這里寫自己郵箱
[root@www ~]# newaliases 重建aliasesdb
[root@www ~]# echo test | mail root 發(fā)送測試軟件給root
[8] 定義yum的非官方庫
在服務(wù)器構(gòu)建的過程中,我們將要用到的一些工具不存在于CentOS中yum的官方庫中,所以需要定義yum的非官方庫文件,讓一些必需的工具通過yum也能夠安裝。
[root@sample ~]# vi /etc/yum.repos.d/dag.repo ← 建立dag.repo,定義非官方庫
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
[root@sample ~]# rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt ← 導(dǎo)入非官方庫的GPG
[9] 停止打印服務(wù)
如果不準(zhǔn)備提供打印服務(wù),停止默認(rèn)被設(shè)置為自動(dòng)啟動(dòng)的打印服務(wù)。
[root@sample ~]# /etc/rc.d/init.d/cups stop ← 停止打印服務(wù)
Stopping cups: [ OK ] ← 停止服務(wù)成功,出現(xiàn)“OK”
[root@sample ~]# chkconfig cups off ← 禁止打印服務(wù)自動(dòng)啟動(dòng)
[root@sample ~]# chkconfig –list cups ← 確認(rèn)打印服務(wù)自啟動(dòng)設(shè)置狀態(tài)
cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off ← 0-6都為off的狀態(tài)就OK(當(dāng)前打印服務(wù)自啟動(dòng)被禁止中)
[10] 停止ipv6
在CentOS默認(rèn)的狀態(tài)下,ipv6是被啟用的狀態(tài)。因?yàn)槲覀儾皇褂胕pv6,所以,停止ipv6,以最大限度保證安全和快速。
首先再次確認(rèn)一下ipv6功能是不是被啟動(dòng)的狀態(tài)。
[root@www ~]# ifconfig -a ← 列出全部網(wǎng)絡(luò)接口信息
sit0 Link encap:IPv6-in-IPv4 ← 確認(rèn)ipv6是被啟動(dòng)的狀態(tài)
[root@www ~]# vi /etc/modprobe.conf← 修改相應(yīng)配置文件,添加如下行到文尾:
alias net-pf-10 off
alias ipv6 off
[root@www ~]# shutdown -r now ← 重新啟動(dòng)系統(tǒng),使設(shè)置生效
修改/etc/yum.repos.d/CentOS-Base.repo,將鏡象站點(diǎn)地址改為在中國的鏡象站點(diǎn)地址。不然我們通過yum安裝軟件速度會(huì)極慢。修改如下
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever – Base
baseurl=http://mirrors.shlug.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#released updates
[updates]
name=CentOS-$releasever – Updates
baseurl=http://mirrors.shlug.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
baseurl=http://mirrors.shlug.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
baseurl=http://mirrors.shlug.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
baseurl=http://mirrors.shlug.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib
baseurl=http://mirrors.shlug.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
protect=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
更新系統(tǒng)[root@www ~]#yum -y upgrade
一些安全的設(shè)置
1、用防火墻關(guān)閉不須要的任何端口,別人PING不到服務(wù)器,威脅自然減少了一大半
防止別人ping的方法:
1)命令提示符下打
echo 1 > /proc/sys/net/ipv4/icmp_ignore_all
2)用防火墻禁止(或丟棄) icmp 包
iptables -A INPUT -p icmp -j DROP
3)對所有用ICMP通訊的包不予響應(yīng)
比如PING TRACERT
2、更改SSH端口,最好改為10000以上,別人掃描到端口的機(jī)率也會(huì)下降
vi /etc/ssh/sshd_config
將PORT改為1000以上端口
同時(shí),創(chuàng)建一個(gè)普通登錄用戶,并取消直接root登錄
useradd ‘username'
passwd ‘username'
vi /etc/ssh/sshd_config
在最后添加如下一句:
PermitRootLogin no #取消root直接遠(yuǎn)程登錄
3、刪除系統(tǒng)臃腫多余的賬號(hào): userdel adm userdel lp userdel sync userdel shutdown userdel halt userdel news userdel uucp userdel operator userdel games userdel gopher userdel ftp 如果你不允許匿名FTP,就刪掉這個(gè)用戶帳號(hào) groupdel adm groupdel lp groupdel news groupdel uucp groupdel games groupdel dip groupdel pppusers
4、更改下列文件權(quán)限,使任何人沒有更改賬戶權(quán)限: chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/group chattr +i /etc/gshadow
5、chmod 600 /etc/xinetd.conf
首先我們創(chuàng)建兩個(gè)普通的用戶tom john
[root@www ~]# useradd tom
[root@www ~]# passwd tom
輸入你的密碼
[root@www ~]# useradd john
[root@www ~]# passwd john
輸入你的密碼
[root@www ~]# usermod -g wheel tom 將tom用戶加入到wheel組中
[root@www ~]# vi /etc/pam.d/su ← 打開這個(gè)配置文件找到這句話在第六行將其前面的#注釋掉
# auth required pam_wheel.so use_uid
[root@www ~]# echo “SU_WHEEL_ONLY yes” >> /etc/login.defs
然后你可以分別用tom和john登陸,沒有加入到wheel組的用戶,執(zhí)行“su -”命令,即使輸入了正確的root密碼,也無法登錄為root用戶
在系統(tǒng)出現(xiàn)錯(cuò)誤或有重要通知發(fā)送郵件給root的時(shí)候,讓系統(tǒng)自動(dòng)轉(zhuǎn)送到我們通常使用的郵箱中,這樣方便查閱相關(guān)報(bào)告和日志。
[root@www ~]# vi /etc/aliases
在這兩句下面mailer-daemon: postmaster
postmaster: root
加入這句話root: zy66289214@126.com 這里寫自己郵箱
[root@www ~]# newaliases 重建aliasesdb
[root@www ~]# echo test | mail root 發(fā)送測試軟件給root
[8] 定義yum的非官方庫
在服務(wù)器構(gòu)建的過程中,我們將要用到的一些工具不存在于CentOS中yum的官方庫中,所以需要定義yum的非官方庫文件,讓一些必需的工具通過yum也能夠安裝。
[root@sample ~]# vi /etc/yum.repos.d/dag.repo ← 建立dag.repo,定義非官方庫
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
[root@sample ~]# rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt ← 導(dǎo)入非官方庫的GPG
[9] 停止打印服務(wù)
如果不準(zhǔn)備提供打印服務(wù),停止默認(rèn)被設(shè)置為自動(dòng)啟動(dòng)的打印服務(wù)。
[root@sample ~]# /etc/rc.d/init.d/cups stop ← 停止打印服務(wù)
Stopping cups: [ OK ] ← 停止服務(wù)成功,出現(xiàn)“OK”
[root@sample ~]# chkconfig cups off ← 禁止打印服務(wù)自動(dòng)啟動(dòng)
[root@sample ~]# chkconfig –list cups ← 確認(rèn)打印服務(wù)自啟動(dòng)設(shè)置狀態(tài)
cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off ← 0-6都為off的狀態(tài)就OK(當(dāng)前打印服務(wù)自啟動(dòng)被禁止中)
[10] 停止ipv6
在CentOS默認(rèn)的狀態(tài)下,ipv6是被啟用的狀態(tài)。因?yàn)槲覀儾皇褂胕pv6,所以,停止ipv6,以最大限度保證安全和快速。
首先再次確認(rèn)一下ipv6功能是不是被啟動(dòng)的狀態(tài)。
[root@www ~]# ifconfig -a ← 列出全部網(wǎng)絡(luò)接口信息
sit0 Link encap:IPv6-in-IPv4 ← 確認(rèn)ipv6是被啟動(dòng)的狀態(tài)
[root@www ~]# vi /etc/modprobe.conf← 修改相應(yīng)配置文件,添加如下行到文尾:
alias net-pf-10 off
alias ipv6 off
[root@www ~]# shutdown -r now ← 重新啟動(dòng)系統(tǒng),使設(shè)置生效
修改/etc/yum.repos.d/CentOS-Base.repo,將鏡象站點(diǎn)地址改為在中國的鏡象站點(diǎn)地址。不然我們通過yum安裝軟件速度會(huì)極慢。修改如下
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever – Base
baseurl=http://mirrors.shlug.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#released updates
[updates]
name=CentOS-$releasever – Updates
baseurl=http://mirrors.shlug.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
baseurl=http://mirrors.shlug.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
baseurl=http://mirrors.shlug.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
baseurl=http://mirrors.shlug.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib
baseurl=http://mirrors.shlug.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
protect=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
更新系統(tǒng)[root@www ~]#yum -y upgrade
一些安全的設(shè)置
1、用防火墻關(guān)閉不須要的任何端口,別人PING不到服務(wù)器,威脅自然減少了一大半
防止別人ping的方法:
1)命令提示符下打
echo 1 > /proc/sys/net/ipv4/icmp_ignore_all
2)用防火墻禁止(或丟棄) icmp 包
iptables -A INPUT -p icmp -j DROP
3)對所有用ICMP通訊的包不予響應(yīng)
比如PING TRACERT
2、更改SSH端口,最好改為10000以上,別人掃描到端口的機(jī)率也會(huì)下降
vi /etc/ssh/sshd_config
將PORT改為1000以上端口
同時(shí),創(chuàng)建一個(gè)普通登錄用戶,并取消直接root登錄
useradd ‘username'
passwd ‘username'
vi /etc/ssh/sshd_config
在最后添加如下一句:
PermitRootLogin no #取消root直接遠(yuǎn)程登錄
3、刪除系統(tǒng)臃腫多余的賬號(hào): userdel adm userdel lp userdel sync userdel shutdown userdel halt userdel news userdel uucp userdel operator userdel games userdel gopher userdel ftp 如果你不允許匿名FTP,就刪掉這個(gè)用戶帳號(hào) groupdel adm groupdel lp groupdel news groupdel uucp groupdel games groupdel dip groupdel pppusers
4、更改下列文件權(quán)限,使任何人沒有更改賬戶權(quán)限: chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/group chattr +i /etc/gshadow
5、chmod 600 /etc/xinetd.conf
您可能感興趣的文章:
- 教你如何搭建一個(gè)安全的Linux服務(wù)器教程
- Linux VPS安全設(shè)置之一 修改SSH端口(CentOS/Debian)
- linux服務(wù)器基本安全配置手冊
- Linux下Nginx安全證書ssl配置方法
- Linux SSH 安全策略 更改 SSH 端口
- 服務(wù)器安全狗Linux版軟件安裝使用說明
- linux服務(wù)器下PHPCMS v9 安全配置詳解
- linux服務(wù)器安全加固shell腳本代碼
- Linux 服務(wù)器安全配置
- 阿里云linux服務(wù)器上使用iptables設(shè)置安全策略的方法
- Linux服務(wù)器下nginx的安全配置詳解
- linux Apache服務(wù)器系統(tǒng)安全設(shè)置與優(yōu)化
- Red Hat Linux 安全設(shè)置方法
- Linux VPS安全設(shè)置之二 禁用ROOT賬戶
- Linux SSH 安全策略 限制 IP 登錄方法
- 安全檢測Unix和Linux服務(wù)器安全設(shè)置入門精講
- Linux下的Apache與PHP安全設(shè)置技巧
- Linux/CentOS服務(wù)器安全配置通用指南
相關(guān)文章
Linux運(yùn)維基礎(chǔ)系統(tǒng)磁盤管理教程
這篇文章主要介紹了Linux運(yùn)維基礎(chǔ)系統(tǒng)磁盤管理教程,附含詳細(xì)的源碼示例,有需要的朋友可以借鑒參考下,希望可以有所幫助,祝大家同學(xué)習(xí)共進(jìn)步2021-09-09
Ubuntu 18.04上安裝 phpMyAdmin的詳細(xì)教程
這篇文章主要介紹了Ubuntu 18.04上安裝 phpMyAdmin的詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
ubuntu中修改grub的啟動(dòng)時(shí)間生成
這篇文章主要介紹了ubuntu中修改grub的啟動(dòng)時(shí)間生成,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Ubuntu/Linux 有關(guān)權(quán)限修改的命令解析
這篇文章主要介紹了Ubuntu/Linux 有關(guān)權(quán)限修改的命令的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11
CentOS設(shè)置靜態(tài)IP的方法總結(jié)
這篇文章主要介紹了CentOS設(shè)置靜態(tài)IP的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-06-06
Apache 新站點(diǎn)目錄配置 SELinux 的方法
本文詳細(xì)介紹了如何使用SELinux保護(hù)Apache新站點(diǎn)目錄,包括確定默認(rèn)上下文、創(chuàng)建和設(shè)置新目錄的上下文、允許網(wǎng)絡(luò)連接以及驗(yàn)證配置,感興趣的朋友跟隨小編一起看看吧2024-11-11
在 Linux 命令行發(fā)送郵件的 5 種方法(推薦)
這篇文章主要介紹了在 Linux 命令行發(fā)送郵件的 5 種方法,本教程中包含了最流行的 5 個(gè)命令行郵件客戶端,你可以選擇其中一個(gè),需要的朋友可以參考下2019-12-12
服務(wù)器安裝寶塔面板無法遠(yuǎn)程連接數(shù)據(jù)庫的解決方法
這篇文章主要介紹了服務(wù)器安裝寶塔面板無法遠(yuǎn)程連接數(shù)據(jù)庫的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06

