天天看點

linux 常見錯誤解決方法

10、pam 

11、拒絕ssh登入(使用者)

a./etc/ssh/sshd_config 

denyusers user

b.pam 中/etc/security/access.conf

/etc/pam.d/sshd

¥¥¥¥¥¥¥¥¥¥¥¥

  一、MBR錯誤。  

¥¥¥¥¥¥¥¥¥¥¥¥¥

二  grub.conf

 三、/etc/inittab

¥¥¥¥¥¥¥¥¥¥¥¥¥

四、

mount /sbin/init /bin/bash   檔案丢失或被替換

¥¥¥¥¥¥¥¥¥¥¥¥¥

五。xwindow錯誤

一般來說與/etc/X11/XF86config檔案有關,考試中不可能涉及硬碟問題。

運作redhat-config-xfree86一般都能解決,可能發生的問題較多,普通點的就是重新整理率,顯

示模式如800x600等。

還有

空間滿和配置檔案無!!

X字型服務(xfs)是否運作

¥¥¥¥¥¥¥¥¥¥¥¥¥

六、

root不能正常登入

********密碼

(一)出現Login incorrect 多半與密碼相關

1、的确是密碼錯誤 單使用者模式修改

2、root使用者被鎖  單使用者模式 usermod -U root 即可

3、沒有root使用者,即沒有uid為0的使用者

4、/etc/securetty檔案中沒有tty*(*表示1,2,3,4等)

5。密碼過期和鎖定

常用的兩種讓 帳戶無法登陸的方法

a.

shadow檔案的 密碼這一位  前面加!!   表示帳戶被鎖 登陸時的提示是 密碼error,logs裡提示是 認證失敗

root:!!$1$3njamFCM$y6axVvkvvw7eS04bfOprz/:12908:0:99999:7:::

解決方法:把!!去掉

b.

shadow 檔案的最後一位 也就是  從1970。1。1号開始 多少天帳号失效 這一位 加具體時間

 root:$1$3njamFCM$y6axVvkvvw7eS04bfOprz/:12908:0:99999:7::1:

如上,表示 1970。1。1後 1 天失效

解決方法: 把1 去掉

d./etc/securitty 定義了

root可安全登入的終端 

e.沒用root使用者,uid=0 使用者不存在

2、user不可登入

同上a. b . c. 

d .存在/etc/nologin空檔案

e.passwd檔案中沒有shell或被替換

f. /etc/bash_profile

g. .bash_profile 中有exit,logout

3、root user都不可登入, /bin/bash被替換或删除

4、檢查pam, /etc/security/access.conf , /etc/pam.d/system-auth,

用authconfig清除設定

無法修改密碼,報unable to lock password file. 錯誤

linux修改不了密碼(包括root帳号),也不能建立新帳号,提示unable to lock password file. 修改passwd, shadow的屬性結果還是一樣

  答:出現該資訊,說明上次更改密碼的程式(passwd)沒有正常退出, 或者現在有另外一個程式正在使用/etc/passwd檔案。可以到/etc下檢視相關的*lock*檔案, 以及passwd檔案的屬性,将相關的lock檔案删除,然後再修改密碼即可。

PAM相關*******

(二)輸入使用者名和密碼後,隻見螢幕一閃,,那多半與authconfig、pam有關了

1、三輪車夫同志遇到的。authconfig時,選了ldap認證,後來ldap伺服器的位址變了後,

就無法登入。

   解決辦法:運作 authconfig取消該選項。

2、/etc/pam.d/system-auth中添加了

   account required /lib/security/$ISA/pam_access.so

   或其他類似的pam模式限制,如pam_listfile.so、pam_time.so等。

  解決辦法同上,運作authconfig後會自動删掉。

3、/etc/pam.d/login中添加了

   account required /lib/security/$ISA/pam_access.so

   或其他類似的pam模式限制,如pam_listfile.so、pam_time.so等。

  解決辦法:隻有手工去檢視login檔案,運作authconfig後不會自動取消。

4、/etc/pam.d/  目錄中的system-auth 或login中的子產品檔案名有誤。

  子產品檔案名錯誤同樣會使系統無法登入。

  建議發生無法登入的情況時,到單使用者或rescue模式,首先檢視/var/log/secure 和

message檔案。

¥¥¥¥¥¥¥¥¥¥¥¥¥

七、

服務的控制:

(一)網絡配置錯誤

      ip addr netmask route gateway 大不了加上tc iptables ipchains 以及相關的配置檔案

(二)DNS解析錯誤

      大多在/etc/host.conf /etc/resolve.conf  /etc/hosts這些檔案有關

(三)xwindow的桌面環境及主要的一次配置檔案.xinitrc、XF86Config、/etc/X11/Xxxx目

錄下面的

(四)磁盤分區,檔案系統,swap分區相關

    (五)診斷和修複其他daemon錯誤(就是各種網絡服務啦),

1、HTTP/HTTPS 

   httpd -t 測試配置檔案

2、SMB 

   testparm 測試配置檔案

3、NFS 

   showmount -e localhost 看自己是否正常提供了exports

   rcpinfo -p localhost   看portmap 是否正常

4、FTP 

   AS3目前自帶vsftpd,配置非常簡單

5、Web proxy 

   AS3目前自帶squid,如果隻是要配置一個簡單的帶認證的web proxy,根據conf檔案

修改非常簡單

6、SMTP

   預設sendmail、也可使用postfix(網易就是用的這個)

7、IMAP, IMAPS, and POP3 

   要簡單使用,幾乎不用配置。

8、SSH 

   /etc/ssh/sshd_config,幾乎每天都要用的東西

9、DNS 

   named-checkconf   named-checkzone檢查配置檔案

   确實找不到問題所在,rpm -ivh --force software.2.x.x.x.rpm

八、一道限制telnet 通路的題目

方法有:

add the following line to the /etc/xinetd.d/telnet configuration file:

no_access = 127.0.0.1

/etc/hosts.deny file in a text editor. Add the following line:

in.telnetd : ALL

/sbin/iptables -A INPUT -s 127.0.0.1 -p tcp --dport 23 -j DROP

九:關于啟動過程中出錯的補充

(一)、mbr損壞或丢失. 進入RESCUE模式,grub-install

linux rescure

grub-install /dev/hda?

(二)、啟動時所需的配置檔案不正确

(要對檔案的内容與格式熟悉)看看"大壞羊"的貼子

Kernel panic : no init found,Try passing init = option to kernel

/boot/grub/grub.conf *************************************************

 grub.conf

grub.conf丢失(隻能用rescue模式)

如果出錯

grub的一般情況

root(hdx,x)錯誤和 根分區(/分區)即root=/dev/xxx不對

記root(hdx,x) 是核心儲存位置即 /boot分區的磁盤。這裡寫法要注意

root=/dev/xxx 是/分區位置

1、如果沒有找到核心(vmlinuz-x.x.x檔案),

  出現File not found

    Press any key to continue....

  說明root(hdx,x)錯誤,或核心檔案名不對

2、如果找到核心後,運作一會,

  出現kernel Panic:Not init Found,

  一般來說是沒有找到根分區(/分區)即root=/dev/xxx不對

3、如果找到核心後,運作一會,

  出現Kernel panic: VFS: Unable to mount root fs on ...,

  一般來說可能忘了加上initrd /initrd-2.4.21-4.EL.img(大多情況發生在使用scsi硬碟)

4、總的來說grub.conf裡面必須存在的就幾行。

#more grub.conf

title linux 

root (hd0,1)                                        #/boot分區所在位置

kernel /vmlinuz-2.4.21-4.EL ro root=/dev/TEST/root #核心和根分區(/分區)位置

(根分區可能是LVM和raid,而不僅是hdx和sdx)

initrd /initrd-2.4.21-4.EL.img

 方法:

root (hd0,1) 

ro root=/dev/TEST/root 要會寫

如果丢失 需要用rescue模式寫這個檔案,至少需要title  root   kernel initrd四句

**************************************************

/etc/inittab

**************************************************

方法:如果不大明白//etc/inittab的格式,強制重裝initscripts的rpm包即可

一般來說就是inittab檔案丢失或者有錯誤。

方法:如果丢失那就到rescue模式下重新安裝,包名initscripts(如果遇到系統有inittab檔案要你恢複出來

 如果出錯,可以到單使用者模式下,修改

注意:

如果不是在rescue模式,修改fstab和inittab檔案時出來Read-only file system咋辦?重新裝載成讀

寫模式

mount -o remount,rw /dev/sdax /

*******************************************************

/etc/fstab   

可以不需要其他方法 ,當出現repaire filesystem時候,輸入密碼,mount -o remount defaults,rw /

*******************************************************

1。啟動rescure模式

2。用fdisk -l看磁盤情況。用e2label /dev/hda?看具體卷标

3。mkdir /mnt/sysimage

4。把所有分區都mount到該目錄下。用man fstab看具體寫法

5。在/etc下建立 fstab檔案。

重新啟動。

*******************************************************

(三)、啟動系統時,所用的檔案或目錄丢失

如:mount ,bash,inittab,init ,/initrd ,/proc

1.mount,bash被替換或删除。 進入RESCUE模式,網絡重新安裝mount,bash包

mount /sbin/init /bin/bash   檔案丢失或被替換

如:

在系統啟動的時候,提示分區無法加載!

經檢查,發現/etc/fstab的資訊是正确的!

分析,可能是/bin/mount 指令被替換!

問,現在如何進行系統的修複!

進入linux rescue 模式:

rpm -Vf --root /mnt/sysimage /bin/mount

你會發現有問題!

rpm -qf --root /mnt/sysimage /bin/mount

查找該檔案屬于哪個RPM安裝包

rpm -ivh --force --root /mnt/sysimage /mnt/source/Redhat/RPMS/packagename.rpm

sync

sync

sync

exit

2./sbin/init 丢失或替換。此檔案在SysVinit*包内,此包還包括如下檔案:/sbin

halt,poweroff,init,runlevel,reboot,shutdown等

init丢失時,(a)、直接啟動時會進入bash2.05#隻讀shell

(b)、用單使用者進入如下提示:

s :s no such file or directory

kernel panic : Attempted to kill init

       修複如mount的修複

3.initscripts*包

啟動的相關檔案:/etc/inittab,/etc/rc.d,/etc/rc.d/rc,rc.sysinit,

/etc/sysconfig/* ,/etc/sysclt.conf, /sbin/ifup,/sbin/ifdown

/sbin/service

# inittab丢失: INIT:no inittab file found.

Enter runlevel:

#/etc/rc.d ,/etc/rc.d/rc 丢失:

用reboot,shutdown,init 6 指令重新開機時有如下明顯提示:

INIT : can not execute "/etc/rc.d/rc"

INIT: no more processes left in this runlevel

按電源重新開機系統,可以到達login界面:

Kernel 2.4.21-15.EL on an i686

( none ) login : 

可以登入,但會提示:

modprobe : modprobe : Can't locate module Char-major-10-224

login(PAM-unix)[22] Session ipened for user root by (uid=0)

-bash: Command not found 

此時沒有網絡,不能修複,主要提示在重新開機的時候,進入rescue模式,

修複後可正常使用,/etc/rc.d丢失,重新安裝initscripts*包,登入時

仍會有提示,但常使用。

#/etc/rc/rc.sysinit 為系統啟動時所用的第一個腳本,若丢失

系統啟動時: 

INIT : can't execute /etc/rc.d/tc.sysinit not found 

及其它提示

#/sbin/ifup,/sbin/ifdown 如果丢失,網絡将無法啟動。

#/sbin/service 若丢失或被替換,任何服務無法啟動。

        需要rescue修複。

4. /initrd 目錄丢失,啟動時有如下提示:

pivotroot: pivotroot (/sysroot,/sysroot/initrd) failed: 2

umount /initrd/proc failed : 2

Freeing unused kernel memory : 164k freed

Kernel panic : no init found,Try passing init = option to kernel

進入rescue模式,建立/initrd 目錄即可    需要rescue修複。

(6)Debug Exercise IV

In this exercise, you'll be practicing with Telnet. The service can be on or off by default. It may be blocked by a firewall. Service may be denied through the /etc/xinetd.d/telnet configuration file or through /etc/hosts.deny. Ideally, you'll be able to check your work through another computer on a LAN.

1.Start Red Hat Linux. Check for the installation of the telnet package with the rpm -q telnet command. Install the telnet RPM if required. 

2.Check your configuration for a firewall with the /sbin/service iptables status command. 

3.If there are iptables rules active on your system, you may want to back them up with the /sbin/iptables-save > filename command. 

4.If you have iptables rules, flush them with the /sbin/iptables -F command. 

5.Check your /etc/hosts.allow and /etc/hosts.deny files. If there are rules related to in.telnetd or ALL services in either file, comment them out. 

6.Check the default status of Telnet with the /sbin/chkconfig --list telnet command. The response should be off or on. Use chkconfig to turn Telnet on if required. 

7.Check the /etc/xinetd.d/telnet configuration file. If there are only_from or no_access directives in this file, comment them out. 

8.Now you should be able to connect to Telnet. Try it from the local computer with the telnet localhost command. You should be able to log in with a local user name and password. Log out of Telnet. 

9.Repeat the telnet access request from a remote computer. Use the name or the IP address of the Telnet server. Log out of Telnet. 

10.On the Telnet server, add the following line to the /etc/xinetd.d/telnet configuration file:

no_access = 127.0.0.1 

11.From the computer with the Telnet server, try the telnet localhost command. What happens? Is a successful login through Telnet unexpected? 

12.Run the /sbin/service xinetd reload command. Repeat step 11. What happens now? If possible, try to use the telnet command to connect to the Telnet server from a different computer on your LAN. Can you connect? 

13.Restore the original /etc/xinetd.d/telnet configuration file and run /sbin/service xinetd reload command again. 

14.Open the /etc/hosts.deny file in a text editor. Add the following line:

in.telnetd : ALL 

15.Repeat step 11. What happens now? Try this again from another computer on your LAN. 

16.Restore the original /etc/hosts.deny file. 

17.Now try to set up a firewall to block yourself from accessing Telnet on the local computer. 

18.Add the following iptables chain to your firewall (the TCP/IP port for Telnet is 23. You can look up the port you need in /etc/services):

/sbin/iptables -A INPUT -s 127.0.0.1 -p tcp --dport 23 -j DROP 

19.Verify that your computer accepted this new rule with the iptables -L command. You should see that packets destined for Telnet are to be dropped. 

20.Repeat step 11. What happens now? Try to log in via Telnet again from another computer on your LAN. 

21.Note how the response is different when you block access through a firewall and through a file such as /etc/hosts.deny. 

22.Restore your original firewall. Flush the rule that you created with the /sbin/iptables -F command. Then restore the old rules if required with the /sbin/iptables-restore < filename command.

繼續閱讀