linux常見問題3

By 人生百味 發表於 2006-11-6 22:48:00

查詢你的CPU等級
====================================
cat /proc/cpuinfo

如何使用戶沒有telnet和ftp權限
====================================
若只希望用戶沒telnet權限,則需要修改/etc/passwd中對應該用戶的shell爲/bin/true。
若只希望用戶沒有telnet和ftp權限,則需要修改/etc/passwd中對應該用戶的shell爲/bin/false。

如何連續執行一個命令
====================================
  使用watch命令,可以反覆執行命令,如果和ls配合,可以達到觀察某文件大小變化的效果。例如:
  $watch ls -l file.name

如何防止某個關鍵文件被修改
====================================
  在linux下,有些配置文件是不允許任何人包括root修改的,爲了防止被誤刪除或修改,可以設定該文件的"不可修改位(immutable)"。
  例如:
  chattr +i /etc/fstab
  如果需要修改文件則:
  chattr -i /etc/fstab
  以後再修改文件。

linux環境下如何undelete
====================================
  先在自己的主目錄下創建一個名爲.trash的子目錄,然後在bashrc加入以下指令:
  alias rm 'mv -f !* ~/.trash'
  alias undel 'mv ~/.trash/!* ./!*'
  alias cleantrash '/bin/rm -rf ~/.trash; mkdir ~/.trash;sync'
  alias lrm 'ls ~/.trash'
  若文檔是直接用rm命令刪除的,理論上 ext2 內 rm 掉的檔案還是可以用 debugfs , ext2ed 救回來的.當然... 被 overwrite 掉就沒救了。

find  如何找出磁盤中某個大小範圍內的文件
find  ====================================
find  比如要查找磁盤中大於3M的文件:
find  find . -size +3000k -exec ls -ld {} ;

如何快速重新執行已經執行過的命令
====================================
  使用!可以實現該功能,例如你前面執行了很多命令,現在突然想執行上一次執行的./configure命令,則只需要輸入“!./con”即可而無需使用上下鍵來滾動查找。
  而!!則能代替前面一個命令。比如剛執行過一次ifconfig,輸入“!!”則等於再執行一次ifconfig。
  而且這兩個用法可以和其他命令組合,比如你剛執行過ifconfig,然後執行man !!,就等於執行man ifconfig。

當終端出現混亂時,如何讓它恢復正常
====================================
  當使用stty命令而出現一些混亂或者更糟的是,使用一個程序而使終端設置完全混亂了時怎麼辦?要回到“現實”,試試下面的命令:
  stty sane
  如果擊鍵變得混亂時,試着用<CTRL+j>來把命令括起來,輸入<CTRL+j>的順序是先按下CTRL再鍵入j鍵。
  <ctrl+j>ctty sane <ctrl+j>
  這個命令不會回到先前的設置,但卻可以去除一些稀奇古怪的設置。而真正會出現什麼設置要依賴於所使用的系統,但它至少會讓你能輸入字符,並見到結果。從這裏開始,你可以把一些組合鍵設置爲你所喜歡的方式。

tar  如何將.gz文件分割爲數個1.44mb
tar  ====================================
tar  把一個文件分割到軟盤:
tar  tar cfvm /dev/fd0 file.tar.gz
tar  把軟盤上的文件合併到硬盤:
tar  tar xvfm /dev/fd0

如何一次處理一整個目錄
====================================
  Linux/UNIX 的很多常用命令如 rm , cp 等都有一個參數---- -r , 是遞歸的意思, 命令里加了參數 -r 就可以對目標目錄及其下所有子目錄進行操作,如:
  rm -rf /test (f 是 force 意爲強行)
  該命令完全刪除根目錄下的子目錄 test ,作用類似於 dos 下的 deltree ,當然使用這個命令時要特別小心。再如:
  cp -r /test /test1
  有類似 dos 下 xcopy /s 的作用。

redhat下如何允許root通過telnet登錄?
====================================
方法1:/etc/securetty ( 加入 pts/0 、pts/1、...)
# echo "pts/0" >> /etc/securetty
方法2:爲了在redhat linux系統中激活遠程登陸,從文件/etc/pam.d/login中移去下面這一行:
auth required /lib/security/pam_security.so
將/etc/securetty這個文件改名就行啦,該文件是定義root只能在tty1~tty6的終端上登錄的,詳細的信息可以"man login"。

reboot  Linux正常重新啓動的方法有很多種,下面介紹幾種常用的重新啓動方法:
reboot  ====================================
reboot  Ctrl+Alt+Del
reboot  #init 6
reboot  #shutdown -r now
reboot  #reboot

爲什麼我的linux不允許普通用戶登錄?
====================================
  以root的身份登錄系統,檢查是不是有/etc/nologin這個文件,刪除這個文件,然後再以普通用戶的身份登錄。相信問題已經解決。
  出現這種問題一般是因爲系統在關閉的過程中意外中斷了操作,如斷線或者是插頭被拔了之類的意外。而系統在關閉的過程中會自動的產生這個文件,以便通知用戶系統正在關閉這就造成普通用戶無法登錄了。
  另外一種原因是系統管理員在對系統進行維護,爲了維護的過程中不受其他用戶的影響,需要生成這個文件來禁止其他用戶登錄。但很不幸系統管理維護完以後忘記刪除這個文件了。

chown  如何改變當前路徑下所有目錄和文件的所有權
chown  ====================================
chown  改變所有子目錄及文件的所有權
chown  #chown -R owner[.group] *
chown  也可以用find命令來實現:
chown  #find . -exec chown owner[.group] {} ;

改變所有子目錄及文件的屬性
在你要改變屬性的目錄下,輸入命令:
#chmod -R 777 *
就可以改變下面所有子目錄及文件的屬性,不過使用這個命令的時候要特別小心,要是在根目錄下打入這個命令,你所有文件的屬性都將改變,這就會引起很大的安全性問題。

如何快速查找文件
====================================
  查找文件可以用find,但最好是用locate,速度快,參數少。
  $locate filename
  它是在一個數據庫裏面查找,所以,要記得經常用updatedb命令更新數據庫。一般地,在crontab中的cron.daily腳本會執行/usr/sbin/logrotate /etc/logrotate.conf命令,讓機子在每天深夜更新數據庫。

如何將Linux或FreeBSD複製到另一顆硬盤 ?
====================================
  Linux上的系統複製很簡單,使用cp -ax將partition資料複製過去,重開機後設定lilo就可以了。
  FreeBSD也可以用cp來複制文檔,但是對於複製整個文檔系統並不是好方法。
  這裏介紹使用dump和restore來做:

創建新的文檔系統
假如你的新硬盤爲ad1, 而將來的根分區將是ad1s1a, 你可以先創建文檔系統:
newfs /dev/ad1s1a
mount /dev/ad1s1a /mnt
cd /mnt

複製:
dump -f- / | restore -f- -r
這是把老的根文檔系統複製輸出到管道,restore從管道里讀數據,寫入當前目錄所在的文檔系統。

按部就班複製其他文檔系統
複製完後,也許 要修改新硬盤下的/etc/fstab,安裝上新的分區,摘下老硬盤就可以了。
再補充一點,如果你要複製的是另外一臺機器,可以用rsh,這樣就可以通過網絡把一個分區數據傳送到另外一臺機器,不需要NFS,不需SAMBA等就可以解決問題,而cp就很難作到了。
newfs /dev/ad1s1a
mount /dev/ad1s1a /mnt
cd /mnt
rsh -l yourname thathost 'dump -f- /' | restore -f- -r

linux怎麼給一個普通用戶reboot權限?
====================================
分四種情況討論:
1.讓任何人(包括根本不擁有系統帳號的人)都可以通過控制檯reboot
在/etc/inittab文件中保留ca::ctrlaltdel:/sbin/shutdown -t3 -r now
這一行。這樣全國人民都可以reboot你的機器,只要你把控制檯交出來。

2.讓所有系統用戶都可以reboot
執行# > /etc/security/console.apps/reboot即可。這就在console.apps目錄下生成了一個空文件,文件名就是授權的application。以上路徑是針對Mandrake系統而言的,其他系統我不清楚。不過,真正高雅的Mandraker或許根本就不會去靠“>”來生成這個文件??????他們會使用msec來進行控制的。

3.讓指定的用戶纔可以reboot
假設我們要讓用戶zhizunbao擁有reboot的權限,我們靠uid/gid來完成控制:
# groupadd reboot
# cd /usr/local
# mkdir reboot
# chown root:reboot reboot/
# chmod 750 reboot/
# cd reboot
# cp /sbin/reboot .
# chmod 4755 reboot
# usermod -G reboot zhizunbao


現在,zhizunbao就可以運行/usr/local/reboot/reboot來重啓動機器。

4.在一臺不設普通用戶的機器上啓用口令驗證reboot
這實際上是靠添加一個關機帳號來實現的,該帳號的shell就是加了s位的/sbin/halt,並且口令只有少數維護人員知道。我們這裏採用的就是第4套方案。

怎樣知道自己的機器上有哪些服務在運行
====================================
若一臺機器運行有很多不需要的服務,那麼被攻擊者入侵的可能性就會大大加大,因此作爲管理員就應該經常查看系統運行有哪些服務。
首先查看系統運行的進程
若需要查看系統當前運行的所有進程,就需要用如下命令:
# ps auxw
其中參數a表示顯示系統中所有用戶的的進程;u表示輸出進程用戶所屬信息;x表示也顯示沒有控制檯的進程;若顯示行太長而被截斷則可以使用f參數;
查看系統監聽的服務
# netstat -ln
l表示顯示當前系統監聽的端口信息;n表示端口按照端口號來顯示,而不轉換爲service文件中定義的端口名;若希望瞭解各個端口都是由哪些進程監聽則可以使用p參數。
  若發現不需要的服務,可以使用linuxconf或ntsysv命令來關閉這些服務在系統啓動時自啓動,然後重新啓動系統則這些服務將在運行。
有些服務是由inetd超級服務器來監控的,則需要標記/etc/inetd.conf來關閉這些服務。

查詢端口對應的服務
====================================
# lsof -i :端口號
查詢此端口對應的服務。

vi 中設置自動縮進
====================================
:set autoindent
:set ai
取消
:set noautoindent
:set noai

如何使linux系統對ping不反應
====================================
  在linux裏,如果要想使ping 沒反應也就是用來忽略icmp包。可以用:
  echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
  若想恢復就用:
  echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

如何實現多網卡bondin
====================================
  使用多塊網卡虛擬成爲一塊網卡,具有相同的IP地址。這項技術其實在sun和cisco中已經存在,分別稱爲Trunking和etherchannel技術,在Linux中,這種技術稱爲bonding。
  因爲bonding在內核2.4.x中已經包含了,只需要在編譯的時候把網絡設備選項中的Bonding driver support選中就可以了。
  然後,重新編譯核心,重新起動計算機,執行如下命令:
  ismod bonding
  ifconfig eth0 down
  ifconfig eth1 down
  ifconfig bond0 ipaddress
  ifenslave bond0 eth0
  ifenslave bond0 eth1
  現在兩塊網卡已經象一塊一樣工作了.這樣可以提高集羣節點間的數據傳輸.
  你最好把這幾句寫成一個腳本,再由/etc/rc.d/rc.local調用,以便一開機就生效.
  bonding對於服務器來是個比較好的選擇,在沒有千兆網卡時,用兩三塊100兆網卡作bonding,可大大提高服務器到交換機之間的帶寬.但是需要在交換機上設置連接bonding網卡的兩個口子映射爲同一個虛擬接口。

Removing ^M from file
======================================================
if you have transferred a file from MS Windows to UNIX, you might find that the file looks like this:
bleh bleh ^M
leh leh ^M
tey tey tey^M
This is because Windows uses carridge return and newline to indicate a new line.
Here are a number of ways to get rid of the ^M characters:
1- cat filename1 | tr -d "^V^M" > newfile
2- sed -e "s/^V^M//" filename > outputfilename
where ^V is actually control-V and ^M is actually control-M (you must type these yourself, don't just copy and paste this command from this web page)
3-vi solution : open file with vi
1. hit the ESC key
2. :%s/^V^M//
3 - some distributions contain a command called dos2unix which removes these carridge return characters
4- use the texteditor vim (www.vim.org) and edit the file. If all the lines (not only some) contain consistently the carridge return characters then vim will show [textmode] and when you change the mode with the command
:set notextmode
it will remove them.

Create /dev/null
====================================
I have moved a file to /dev/null and now my system doesn't work
If you move a file with the mv command to "/dev/null" then it will be overwritten with an ordinary file.
How to fix it:
Boot your system. If it doesn't boot take a one disk distribution like Toms rtbt and mount your /dev/hdXX partition.
Now type in a shell "mknod /dev/null c 1 3" to create a nod file. /dev/null is the path where the nod file will be saved. The c stands for a character device and the two numbers are the major and the minor numbers for the null device.
After that you must change with "chmod 666 /dev/null" the read, write and execute permissions.
With "ls -alF /dev/" you will see all nod files with it's own three parameters like
"crw-rw-rw- 1 root root 1, 3 Oct 4 11:34 null ".
You will see a "c" in the near of the rwx flags an a " 1, 3" left of the date.

Howto log in to your server passwordless via ssh ( rsa version )
====================================
Create your private and public keys via ssh-keygen program
$ ssh-keygen
Computing keys
Testing the keys..
Key generation complete..
Enter the file in which to save the key (/usr/home/murat/.ssh/identity)
Press enter for the default value...
Your identification has been saved in /usr/home/murat/.ssh/identity
Your public ket is:
blah....blah...blah....
Your public key has been saved in /usr/home/murat/.ssh/identity.pub
Now that we have created our `public` key, take your
public key which is ~/.ssh/identity.pub to your server,
in the ~/.ssh/ directory, create a file named authorized_keys
and append the content of identity.pub file to your authorized_keys file
now, in your machine, type
$ ssh -l username your_remote_machine.domain.com
Boom, no password, no headache, you're in the other side...;)

Blocking anyone to su to root
====================================
The su (Substitute User) command allows you to become other existing
users on the system. For example you can temporarily
become "root" and execute commands as the super-user "root". If
you don't want anyone to su to root or restrict "su" command to
certain users then add the following two lines to the top of
your "su" configuration file in the "/etc/pam.d/" directory.
1- Edit the su file (vi /etc/pam.d/su) and add the following two
lines to the top of the file:
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=wheel
After adding the two lines above, the "/etc/pam.d/su" file should
look like this:
#%PAM-1.0
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
Which means only those who are a member of the "wheel" group can su to root;
and to add a user to wheel group use:
root# usermod -G10 username
Ok, now everybody can not be root using su. When an user that is not in wheel group runs su command ,he/she can not be root even if he/she writes correct root password.

Disable reboot,halt ,shutdown for users
====================================
On Redhat
[root@apache /]# rm -f /etc/security/console.apps/halt
[root@apache /]# rm -f /etc/security/console.apps/poweroff
[root@apache /]# rm -f /etc/security/console.apps/reboot
[root@apache /]# rm -f /etc/security/console.apps/shutdown
[root@apache /]# rm -f /etc/security/console.apps/xserver (if removed, root will be the only user able to start x).

mkdir -p rep1/rep2/rep3 一次建多個目錄

rm -rf /tmp/.??* /tmp/* 刪除所有文件,包括隱藏文件
You can put this into /etc/rc.d/init.d/syslog into the "stop)" section. This will clean up /tmp at every shutdown and keep your disk tidy.
Do not run the above command while running X11 or before you run startx. X11 needs the /tmp/.font-unix which is created by xfont server and X11 it self creates the directory /tmp/.X11-unix which is needed to talk to the X11 windows.

 

1、BIOS的安全設置

  這是最基本的了,也是最簡單的了。一定要給你的BIOS設置密碼,以防止通過在BIOS中改變啓動順序,而可以從軟盤啓動。這樣可以阻止別有用心的試圖用特殊的啓動盤啓動你的系統,還可以阻止別人進入BIOS改動其中的設置,使機器的硬件設置不能被別人隨意改動。

  2、LILO的安全設置

  LILO是LInux

  LOader的縮寫,它是LINUX的啓動模塊。可以通過修改“/etc/lilo.conf”文件中的內容來進行配置。在 /etc/lilo.conf文件中加如下面兩個參數:restricted,password。這三個參數可以使你的系統在啓動lilo時就要求密碼驗證。

  第一步:編輯lilo.conf文件(vi /etc/lilo.comf),假如或改變這三個參數:
  boot=/dev/hda
  map=/boot/map
  install=/boot/boot.b
  prompt
  timeout=00 #把這行該爲00,這樣系統啓動時將不在等待,而直接啓動LINUX
  message=/boot/message
  linear
  default=linux
  restricted #加入這行
  password= #加入這行並設置自己的密碼

  image=/boot/vmlinuz-2.4.2-2
  label=linux
  root=/dev/hda6
  read-only

  第二步:因爲"/etc/lilo.conf"文件中包含明文密碼,所以要把它設置爲root權限讀取。
  # chmod 0600 /etc/lilo.conf

  第三步:更新系統,以便對“/etc/lilo.conf”文件做的修改起作用。
  # /sbin/lilo -v

  第四步:使用“chattr”命令使"/etc/lilo.conf"文件變爲不可改變。
  # chattr +i /etc/lilo.conf

  這樣可以在一定程度上防止對“/etc/lilo.conf”任何改變(意外或其他原因)

  3、讓口令更加安全

  口令可以說是系統的第一道防線,目前網上的大部分對系統的攻擊都是從截獲口令或者猜測口令開始的,所以我們應該選擇更加安全的口令。


  首先要杜絕不設口令的帳號存在。這可以通過查看/etc/passwd文件發現。例如,存在的用戶名爲test的帳號,沒有設置口令,則在/etc/passwd文件中就有如下一行:
  test::100:9::/home/test:/bin/bash

  其第二項爲空,說明test這個帳號沒有設置口令,這是非常危險的!應將該類帳號刪除或者設置口令。
其次,在舊版本的linux中,在/etc/passwd文件中是包含有加密的密碼的,這就給系統的安全性帶來了很大的隱患,最簡單的方法就是可以用暴力破解的方法來獲得口令。可以使用命令/usr/sbin/pwconv或者/usr/sbin/grpconv來建立/etc/shadow或者 /etc/gshadow文件,這樣在/etc/passwd文件中不再包含加密的密碼,而是放在/etc/shadow文件中,該文件只有超級用戶 root可讀!

  第三點是修改一些系統帳號的Shell變量,例如uucp,ftp和news等,還有一些僅僅需要FTP功能的帳號,一定不要給他們設置/bin/bash或者/bin/sh等Shell變量。可以在/etc/passwd中將它們的Shell變量置空,例如設爲 /bin/false或者/dev/null等,也可以使用usermod -s /dev/null username命令來更改username的 Shell爲/dev/null。這樣使用這些帳號將無法Telnet遠程登錄到系統中來!

  第四點是修改缺省的密碼長度:在你安裝linux時默認的密碼長度是5個字節。但這並不夠,要把它設爲8。修改最短密碼長度需要編輯login.defs文件(vi/etc/login.defs),把下面這行
  PASS_MIN_LEN 5
  改爲
  PASS_MIN_LEN 8
  login.defs文件是login程序的配置文件。

  4、自動註銷帳號的登錄


  在unix系統中root賬戶是具有最高特權的。如果系統管理員在離開系統之前忘記註銷root賬戶,那將會帶來很大的安全隱患,應該讓系統會自動註銷。通過修改賬戶中“TMOUT”參數,可以實現此功能。TMOUT按秒計算。編輯你的profile文件(vi /etc/profile),在 "HISTFILESIZE="後面加入下面這行:
  TMOUT=300

  300,表示300秒,也就是表示5分鐘。這樣,如果系統中登陸的用戶在5分鐘內都沒有動作,那麼系統會自動註銷這個賬戶。你可以在個別用戶的“.bashrc”文件中添加該值,以便系統對該用戶實行特殊的自動註銷時間。

  改變這項設置後,必須先註銷用戶,再用該用戶登陸才能激活這個功能。

  5、取消普通用戶的控制檯訪問權限

  你應該取消普通用戶的控制檯訪問權限,比如shutdown、reboot、halt等命令。
  # rm -f /etc/security/console.apps/
  是你要註銷的程序名。

  6、取消並反安裝所有不用的服務

  取消並反安裝所有不用的服務,這樣你的擔心就會少很多。察看“/etc/inetd.conf”文件,通過註釋取消所有你不需要的服務(在該服務項目之前加一個“#”)。然後用“sighup”命令升級“inetd.conf”文件。

  第一步:

  更改“/etc/inetd.conf”權限爲600,只允許root來讀寫該文件。
  # chmod 600 /etc/inetd.conf

  第二步:

  確定“/etc/inetd.conf”文件所有者爲root。

  第三步:

  編輯 /etc/inetd.conf文件(vi /etc/inetd.conf),取消下列服務(你不需要的):ftp, telnet,  shell, login, exec, talk, ntalk, imap, pop-2, pop-3, finger, auth等等。把不需要的服務關閉可以使系統的危險性降低很多。


  第四步:

  給inetd進程發送一個HUP信號:
  # killall -HUP inetd

  第五步:

  用chattr命令把/ec/inetd.conf文件設爲不可修改,這樣就沒人可以修改它:
  # chattr +i /etc/inetd.conf

   這樣可以防止對inetd.conf的任何修改(以外或其他原因)。唯一可以取消這個屬性的人只有root。如果要修改inetd.conf文件,首先要是取消不可修改性質:
  # chattr -i /etc/inetd.conf

  別忘了該後再把它的性質改爲不可修改的。

  7、TCP_WRAPPERS

  使用TCP_WRAPPERS可以使你的系統安全面對外部入侵。最好的策略就是阻止所有的主機("/etc/hosts.deny"文件中加入 "ALL: ALL@ALL, PARANOID" ),然後再在"/etc/hosts.allow" 文件中加入所有允許訪問的主機列表。

  第一步:

  編輯hosts.deny文件(vi /etc/hosts.deny),加入下面這行
  # Deny access to everyone.
  ALL: ALL@ALL, PARANOID

  這表明除非該地址包在允許訪問的主機列表中,否則阻塞所有的服務和地址。

  第二步:

  編輯hosts.allow文件(vi /etc/hosts.allow),加入允許訪問的主機列表,比如:
  ftp: 202.54.15.99 foo.com
  202.54.15.99和 foo.com是允許訪問ftp服務的ip地址和主機名稱。

  第三步:

  tcpdchk程序是tepd wrapper設置檢查程序。它用來檢查你的tcp wrapper設置,並報告發現的潛在的和真實的問題。設置完後,運行下面這個命令:
  # tcpdchk

  8、修改“/etc/host.conf”文件

  “/etc/host.conf”說明了如何解析地址。編輯“/etc/host.conf”文件(vi /etc/host.conf),加入下面這行:
  # Lookup names via DNS first then fall back to /etc/hosts.
  order bind,hosts
  # We have machines with multiple IP addresses.
  multi on
  # Check for IP address spoofing.
  nospoof on

  第一項設置首先通過DNS解析IP地址,然後通過hosts文件解析。第二項設置檢測是否“/etc/hosts”文件中的主機是否擁有多個IP地址(比如有多個以太口網卡)。第三項設置說明要注意對本機未經許可的電子欺騙。

  9、使“/etc/services”文件免疫

  使“/etc/services”文件免疫,防止未經許可的刪除或添加服務:
  # chattr +i /etc/services

  10、不允許從不同的控制檯進行root登陸

  "/etc/securetty"文件允許你定義root用戶可以從那個TTY設備登陸。你可以編輯"/etc/securetty"文件,再不需要登陸的TTY設備前添加“#”標誌,來禁止從該TTY設備進行root登陸。

  在/etc/inittab文件中有如下一段話:
  # Run gettys in standard runlevels
  1:2345:respawn:/sbin/mingetty tty1
  2:2345:respawn:/sbin/mingetty tty2
  #3:2345:respawn:/sbin/mingetty tty3
  #4:2345:respawn:/sbin/mingetty tty4
  #5:2345:respawn:/sbin/mingetty tty5
  #6:2345:respawn:/sbin/mingetty tty6

  系統默認的可以使用6個控制檯,即Alt+F1,Alt+F2...,這裏在3,4,5,6前面加上“#”,註釋該句話,這樣現在只有兩個控制檯可供使用,最好保留兩個。然後重新啓動init進程,改動即可生效!

  11、使用PAM(可插拔認證模塊)禁止任何人通過su命令改變爲root用戶su(Substitute

  User替代用戶)命令允許你成爲系統中其他已存在的用戶。如果你不希望任何人通過su命令改變爲root用戶或對某些用戶限制使用su命令,你可以在su配置文件(在"/etc/pam.d/"目錄下)的開頭添加下面兩行:
編輯su文件(vi /etc/pam.d/su),在開頭添加下面兩行:
  auth sufficient /lib/security/pam_rootok.so
  auth required /lib/security/Pam_wheel.so group=wheel

  這表明只有"wheel"組的成員可以使用su命令成爲root用戶。你可以把用戶添加到“wheel”組,以使它可以使用su命令成爲root用戶。添加方法可以用這個命令:chmod -G10 username 。

  12、Shell logging Bash

  shell在“~/.bash_history”(“~/”表示用戶目錄)文件中保存了500條使用過的命令,這樣可以使你輸入使用過的長命令變得容易。每個在系統中擁有賬號的用戶在他的目錄下都有一個“.bash_history”文件。bash
shell應該保存少量的命令,並且在每次用戶註銷時都把這些歷史命令刪除。

  第一步:

  “/etc/profile”文件中的“HISTFILESIZE”和“HISTSIZE”行確定所有用戶的“.bash_history”文件中可以保存的舊命令條數。強烈建議把把“/etc/profile”文件中的“HISTFILESIZE”和“HISTSIZE”行的值設爲一個較小的數,比如 30。編輯profile文件(vi/etc/profile),把下面這行改爲:
  HISTFILESIZE=30
  HISTSIZE=30

  這表示每個用戶的“.bash_history”文件只可以保存30條舊命令。

  第二步:


  網管還應該在"/etc/skel/.bash_logout" 文件中添加下面這行"rm -f $HOME/.bash_history" 。這樣,當用戶每次註銷時,“.bash_history”文件都會被刪除。

  編輯.bash_logout文件(vi /etc/skel/.bash_logout) ,添加下面這行:
  rm -f $HOME/.bash_history

  13、禁止Control-Alt-Delete鍵盤關閉命令

  在"/etc/inittab" 文件中註釋掉下面這行(使用#):
  ca::ctrlaltdel:/sbin/shutdown -t3 -r now
  改爲:
  #ca::ctrlaltdel:/sbin/shutdown -t3 -r now

  爲了使這項改動起作用,輸入下面這個命令:
  # /sbin/init q

  14、給"/etc/rc.d/init.d" 下script文件設置權限

  給執行或關閉啓動時執行的程序的script文件設置權限。
  # chmod -R 700 /etc/rc.d/init.d/*

  這表示只有root才允許讀、寫、執行該目錄下的script文件。

  15、隱藏系統信息

  在缺省情況下,當你登陸到linux系統,它會告訴你該linux發行版的名稱、版本、內核版本、服務器的名稱。對於黑客來說這些信息足夠它入侵你的系統了。你應該只給它顯示一個“login:”提示符。

  首先編輯"/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.
  #e cho "" > /etc/issue
  #e cho "$R" >> /etc/issue

 

 #e cho "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue
  #
  #cp -f /etc/issue /etc/issue.net
  #e cho >> /etc/issue

  其次刪除"/etc"目錄下的“isue.net”和"issue"文件:
  # rm -f /etc/issue
  # rm -f /etc/issue.net

  16、禁止不使用的SUID/SGID程序

  如果一個程序被設置成了SUID

  root,那麼普通用戶就可以以root身份來運行這個程序。網管應儘可能的少使用SUID/SGID 程序,禁止所有不必要的SUID/SGID程序。

  查找root-owned程序中使用's'位的程序:
  # find / -type f ( -perm -04000 -o -perm -02000 ) -exec ls -lg {} /;

  用下面命令禁止選中的帶有's'位的程序:
  # chmod a-s [program]

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章