CentOS安全設定

來源:互聯網
上載者:User

1、用防火牆關閉不須要的任何連接埠,別人PING不到伺服器,威脅自然減少了一大半。

防止別人ping的方法:

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

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

先用/sbin/ifconfig查看網卡資訊,找到外網網卡名字,如eth0
運行
iptables -A OUTPUT -o eth0 -p icmp -j ACCEPT
iptables -A INPUT -i eth0 -p icmp -icmp-type echo-reply -j ACCEPT
iptables -A INPUT -i eth0 -p icmp -icmp-type echo-request -j DROP
service iptables save

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

2、更改SSH連接埠,最好改為10000以上,別人掃描到連接埠的機率也會下降
vi /etc/ssh/sshd_config
將PORT改為1000以上連接埠

同時,建立一個普通登入使用者,並取消直接root登入
useradd newuser
passwd newuser
usermod -G 10 newuser

usermod -G wheel newuser
//將使用者加入wheel組,允許使用 su - 命令提權成root

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

vi /etc/pam.d/su
#auth required pam_wheel.so use_uid ← 找到此行,去掉行首的“#”
echo 'SU_WHEEL_ONLY yes' >> /etc/login.defs //以上為禁止不在wheel組的使用者使用su -命令
重啟sshd服務
service sshd restart

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

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

5、chmod 600 /etc/xinetd.conf
vi /etc/xinetd.conf 禁止所有不需要的服務,如:ftp、telnet、shell、login、exec、talk、ntalk、imap、pop-2、pop-3、finger、auth等等,也可以直接通過setup命令來設定服務項。
改變了“xinetd.conf”檔案之後,別忘了給inetd進程發一個SIGHUP訊號:
killall -HUP xinetd
chattr +i /etc/xinetd.conf //把inetd.conf設成不可改變,如果要改變xinetd.conf檔案,你必須先清除這個不允許改變的標誌:
chattr -i /etc/inetd.conf

6、關閉FTP匿名使用者登陸,以上介紹CentOS安全設定。

編輯“host.conf”檔案(vi /etc/host.conf)加入下面這些行:
order bind,hosts
multi on
nospoof on

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.