centos 5.1下的安全設定(適合所有的linux版本)

來源:互聯網
上載者:User

在 一般情況下,一般使用者通過執行“su -”命令、輸入正確的root密碼,可以登入狀態root使用者來對系統進行管理員層級的配置。但是,為了更進一步加強系統的安全性,有必要建立一個管理員的 組,只允許這個組的使用者來執行“su -”命令登入狀態root使用者,而讓其他組的使用者即使執行“su -”、輸入了正確的root密碼,也無法登入狀態root使用者。在UNIX下,這個組的名稱通常為“wheel”。
首先我們建立兩個普通的使用者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  ← 開啟這個設定檔找到這句話在第六行將其前面的#注釋掉
# auth required pam_wheel.so use_uid
[root@www ~]# echo “SU_WHEEL_ONLY yes” >> /etc/login.defs
然後你可以分別用tom和john登陸,沒有加入到wheel組的使用者,執行“su -”命令,即使輸入了正確的root密碼,也無法登入狀態root使用者
在系統出現錯誤或有重要通知發送郵件給root的時候,讓系統自動轉送到我們通常使用的郵箱中,這樣方便查閱相關報告和日誌。
[root@www ~]# vi /etc/aliases
在這兩句下面mailer-daemon: postmaster
postmaster: root
加入這句話root: zy66289214@126.com 這裡寫自己郵箱
[root@www ~]# newaliases 重建aliasesdb
[root@www ~]# echo test | mail root 發送測試軟體給root
[8] 定義yum的非官方庫

  在伺服器構建的過程中,我們將要用到的一些工具不存在於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  ← 匯入非官方庫的GPG
[9] 停止列印服務

  如果不準備提供列印服務,停止預設被設定為自動啟動的列印服務。

[root@sample ~]# /etc/rc.d/init.d/cups stop  ← 停止列印服務
Stopping cups:            [ OK ]    ← 停止服務成功,出現“OK”

[root@sample ~]# chkconfig cups off  ← 禁止列印服務自動啟動

[root@sample ~]# chkconfig –list cups  ← 確認列印服務自啟動設定狀態
cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off  ← 0-6都為off的狀態就OK(當前列印服務自啟動被禁止中)
[10] 停止ipv6

  在CentOS預設的狀態下,ipv6是被啟用的狀態。因為我們不使用ipv6,所以,停止ipv6,以最大限度保證安全和快速。

  首先再次確認一下ipv6功能是不是被啟動的狀態。

[root@www ~]# ifconfig -a ← 列出全部網路介面資訊
sit0 Link encap:IPv6-in-IPv4 ← 確認ipv6是被啟動的狀態
[root@www ~]# vi /etc/modprobe.conf← 修改相應設定檔,添加如下行到文尾:
alias net-pf-10 off
alias ipv6 off
[root@www ~]# shutdown -r now  ← 重新啟動系統,使設定生效
修改/etc/yum.repos.d/CentOS-Base.repo,將鏡象網站地址改為在中國的鏡象網站地址。不然我們通過yum安裝軟體速度會極慢。修改如下
# 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

更新系統[root@www ~]#yum -y upgrade
一些安全的設定
1、用防火牆關閉不須要的任何連接埠,別人PING不到伺服器,威脅自然減少了一大半

防止別人ping的方法:

1)命令提示字元下打
echo 1 > /proc/sys/net/ipv4/icmp_ignore_all

2)用防火牆禁止(或丟棄) icmp 包
iptables -A INPUT -p icmp -j DROP

3)對所有用ICMP通訊的包不予響應
比如PING TRACERT

2、更改SSH連接埠,最好改為10000以上,別人掃描到連接埠的機率也會下降

vi /etc/ssh/sshd_config
將PORT改為1000以上連接埠

同時,建立一個普通登入使用者,並取消直接root登入
useradd ‘username'
passwd ‘username'

vi /etc/ssh/sshd_config
在最後添加如下一句:
PermitRootLogin no #取消root直接遠程登入

3、刪除系統臃腫多餘的帳號: userdel adm userdel lp userdel sync userdel shutdown userdel halt userdel news userdel uucp userdel operator userdel games userdel gopher userdel ftp 如果你不允許匿名FTP,就刪掉這個使用者帳號 groupdel adm groupdel lp groupdel news groupdel uucp groupdel games groupdel dip groupdel pppusers

4、更改下列檔案許可權,使任何人沒有更改賬戶許可權: chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/group chattr +i /etc/gshadow

5、chmod 600 /etc/xinetd.conf

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.