You are on page 1of 8

Linux 系統安全設定

目錄:
Choose a right Password...........................................................2
The password length..................................................................2
The root account.....................................................................................................2
Set login time out for the root account...................................................................2

系統提供的網路 Service..........................................................2

使用 TCP Wrapper 來保護 inetd 執行服務 .........................3

檔案 :/etc/services.......................................................................3

砍掉用不到的使用者帳戶 ......................................................3

限定可以使用 su 為 root........................................................4
Resource limits...........................................................................4
Shell logging...............................................................................5
The“/etc/lilo.conf“file................................................................5
Disable the Control-Alt-Delete keyboard shutdown
command....................................................................................6
The “/etc/rc.d/rc.local”file.........................................................7
Prevent your system from responding to ping request...........7

1
Choose a right Password
檔案:/etc/passwd 與/etc/shadow
當然,每一個人對於自己的帳號都會有一各相對應的 password。為了安全上的起見,這裡有幾個準
則:
(1) password 的長度不要太短,最好別短於 6 個字,要不然很容易被猜中,而其中一個字母最好為數
字或者為特殊符號。
(2) password 最好是沒有意義的字串。要不然也是很容易就遭人破解。
(3) 時常更換 password。這樣會更安全。

The password length


檔案:/etc/login.defs
再你剛安裝完系統時,系統引許你所輸入的password的長度最少為五個字母。但這系統的最小長
度是可以更改的。若你想要修改其最小長度時,請修改/etc/login.defs。比如最小長度原來為五個字
母,你想把它換為八個字母長度時,就改PASS_MIN_LEN 5 為 PASS_MIN_LEN 8。

The root account


對系統而言,root這個帳號是相同於”超級使用者”。也就是系統並沒有對root的所作所為有所限制。
因為系統假設root曉得自己在做什麼。為了安全上的理由,千萬不要遠端 login 時,就用root的身分
登入,因為這可能導致於密碼在網路上傳輸時遭到竊取。而且記得在你離開你的座位前,登出root。

Set login time out for the root account


檔案:/etc/profile或者$home/.bashrc或$home/.profile
為了防止你在離開你的座位時忘了登出”root”,我們可以在我們的.porfile做一下設定,那樣一來,經
過一段時間後,系統自動會幫你做登出。例如:修改/$home/.profile中的TIMEOUT=7200(單位:秒),那
麼系統在經過2小時後發現這帳號都沒有活動時,就自動幫你登出。)

系統提供的網路 Service
檔案:/etc/inetd.conf
系統所提供的網路Service都定義再這邊,比如說telnet,ftp都定在這邊。如果你想停掉telnet的服務
只要在telnet那一行剛開始加上”#”,就可以了。別忘了修改之後要重新讓inetd重新啟動(killall –
HUP indetd)。

2
使用 TCP Wrapper 來保護 inetd 執行服務
檔案:/etc/hosts.allow與/etc/hosts.deny
透過修改上述兩個檔案來做控管哪些服務(service)與哪些人可以接受inetd所提供的服務。例如在:
/etc/hosts.deny檔中:
ALL:ALL(daemon list:client list)
這行代表的意思為告訴 Tcp Wrapper禁止所有的服務為所有的主機所存取。

檔案:/etc/services
這個檔案定義了在/etc/inet.conf中所提供的服務 listen 的 port。如果你想讓service在不同的 port上
服務,只需修改這邊就可以了。例
ftp 21/tcp
fsp 21/udp fspd

砍掉用不到的使用者帳戶
在系統剛建好時,系統會為你建立了一些系統帳號。為了安全起見,最好把不會用到的帳號停用掉
(disable)。例如:
[root@deep /]# userdel adm
[root@deep /]# userdel lp
[root@deep /]# userdel sync
[root@deep /]# userdel shutdown
[root@deep /]# userdel halt
[root@deep /]# userdel news
[root@deep /]# userdel uucp
[root@deep /]# userdel operator
[root@deep /]# userdel games (delete this user if you don’t use X Window
Server).
[root@deep /]# userdel gopher
[root@deep /]# userdel ftp (delete this user if you don’t use ftp anonymous
server).
停用Group
[root@deep /]# groupdel adm

[root@deep /]# groupdel lp

[root@deep /]# groupdel news

[root@deep /]# groupdel uucp

[root@deep /]# groupdel games (delete this group if you don’t use X Window Server).

[root@deep /]# groupdel dip

[root@deep /]# groupdel pppusers

[root@deep /]# groupdel popusers (delete this group if you don’t use pop server for email).

3
[root@deep /]# groupdel slipusers

限定可以使用 su 為 root
檔案:/etc/pam.d/su
為了安全的起見,並不是所有的人都可以使用 su 成為 root,儘管說他有root的密碼。例下:(修
改/etc/pam.d/su)
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=wheel
auth required /lib/security/pam_pwdb.so shadow nullok
account required /lib/security/pam_pwdb.so
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_pwdb.so shadow use_authtok nullok
session required /lib/security/pam_pwdb.so
session optional /lib/security/pam_xauth.so
注意前面兩行,那邊限定了唯有group為wheel的使用者,才有資格使用 su 好變換身分為root。

Resource limits
檔案:/etc/security
它可用來控制和限制使用者系統使用的資源。修改步驟如下:(super user “root”不會受此限制)

Step1
編輯 limits.conf ,加入
* hard core 0 禁止創造 core file
* hard rss 5000 限制 memory 使用區間到 5M
* hard nproc 20 限制 process 的個數 20
“*”指所有 logs in 的 users

透過這樣的配額限制 , 你將獲得更多對 user 的 process, core file, memory


usage 的控制

Step2
編輯 “/etc/pam.d/login ,加入
session required /lib/security/pam_limits.so
並在最後加入 #
#%PAM-1.0
auth required /lib/security/pam_securetty.so
auth required /lib/security/pam_pwdb.so shadow nullok

4
auth required /lib/security/pam_nologin.so
account required /lib/security/pam_pwdb.so
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_pwdb.so nullok use_authtok md5 shadow
session required /lib/security/pam_pwdb.so
# session optional /lib/security/pam_console.so

Shell logging
在每個 user 的目錄下,有一個 .bash_history 的檔案,上面記錄了 user 所下過的指令與檔案,其
中有可能包含 password 的 plain text 。
修正步驟如下:
Step 1
在 ”/etc/profile”下,最 HISTFILESIZE 和 HISTSIZE 的位置更改設定值
HISTFILESIZE=20
HISTSIZE=20
設定 20 的主要目的是限定所記錄的 command 行數
Step2
管理者要在 “/etc/skel/.bash_logout”下加入一行
rm –f $Home/.bash_history
意思是在 user 離開後,即清除.bash_history 的記錄,避免被其它人使用

The“/etc/lilo.conf“file
檔案: /etc/lilo.conf
Lilo 是 boot loader 最常使用的檔案, 他管理了 boot process ,就像一個 “boot manager”的
角色。
Lilo 位於”/etc”下,透過修改 configuration 可增強系統的安全
加入一行
Adding:timeout:00
上一行意思是說 lilo 在開機時等待使用者輸入的時間(in second)
Adding restricted
這個指令要求使用者在開機時 lilo 執行一些特別的 commamd,如 lili –s 時,會尋問要求輸入
password
Adding:passwprd=<password>
加這一行是要求您輸入上述的 password

Step1

5
Edit lilo.conf (“/etc/lilo.conf”) 加入上述的指令:

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=00 change 00
linear
default=linux
restrict add this line
passwprd=<password> add your password
image=/boot/vmlinuz-2.2.14-5.0
label=linux
read-only
root=/dev/hda6

Step2
因為 “/etc/lilo.conf”包含了沒有加密的 password , 因此我們必需將此設定只有 super user
可以使用 lilo.conf 這個檔

[root@localhost/]# chmod 600 /etc/lilo.conf

Step3
現在我們要更新 lilo 檔,使其啟動
[root@localhost/]#/sbin/lilo –v

Step4
設定 lilo.conf 永遠不會被改變

[root@localhost/]# chattr +i /etc/lilo.conf


如果您要取消這限制

[root@localhost/]# chattr -i /etc/lilo.conf

Disable the Control-Alt-Delete keyboard shutdown command


檔案: /etc/inittab
在 ”/etc/inittab”有一行

6
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
給它加一個#
# ca::ctrlaltdel:/sbin/shutdown -t3 -r now
就可以 Disable 這個動作了
執行
[root@localhost/]#/sbin/init q 使其生效

The “/etc/rc.d/rc.local”file
檔案: /etc/rc.d/rc.local
當我們進入 linux box 時 , 系統會告訴我們 linux server 的 name , version , kernel 版本.如果您覺得
這提供太多的資訊,我們可以修改一些設定使這些資料在 user 登入時不會 show
Step1
Edit “/etc/rc.d/rc.local” 在下列加入”#”
# This will overwrite /etc/issue at every boot. So, make any changes you
# want to make to /etc/issue here or you will lose them when you reboot.
#echo "" > /etc/issue
#echo "$R" >> /etc/issue
#echo "Kernel $(uname -r) on $a $SMP$(uname -m)" >> /etc/issue
#cp -f /etc/issue /etc/issue.net
#echo >> /etc/issue

Step2
移除 “/etc”下的“issue.net” 和 “issue”
[root@localhost/]#rm –f /etc/issue
[root@localhost/]#rm –f /etc/issue.net

Prevent your system from responding to ping request

主要功能是不要讓你的系統對 “ping”做出回應的動作,也就是任何人都 ping 不到你,而你也不


會做任何回應

在 Redhat 6.1 下
[root@localhost/]#echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all
就可以不對 ping 做回應
[root@localhost/]#echo 0>/proc/sys/net/ipv4/icmp_echo_ignore_all
就回到原來的正常狀態

7
在 Redhat 6.2 下
Edit “/etc/sysctl.conf ,並加入這一行
net.ipv4.icmp_echo_ignore_all=1

這時,您必須 restart network 使其生效,方法如下:


[root@localhost/]#/etc/rc.d/init.d/network restart
如需回復將 1 改成 0 即可
net.ipv4.icmp_echo_ignore_all=0

You might also like