自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Centos8中恢復(fù)根目錄為默認(rèn)權(quán)限

系統(tǒng) Linux
本文中介紹如何從意外運(yùn)行# chmod -R 777 /命令,在Centos8操作系統(tǒng)上恢復(fù)默認(rèn)權(quán)限。本文中我們將故意在一個(gè)測(cè)試服務(wù)器上運(yùn)行chmod 777命令,并嘗試通過(guò)運(yùn)行兩個(gè)命令進(jìn)行恢復(fù)。

本文中介紹如何從意外運(yùn)行# chmod -R 777 /命令,在Centos8操作系統(tǒng)上恢復(fù)默認(rèn)權(quán)限。

本文中我們將故意在一個(gè)測(cè)試服務(wù)器上運(yùn)行chmod 777命令,并嘗試通過(guò)運(yùn)行兩個(gè)命令進(jìn)行恢復(fù)。就是如下兩條命令:

  1. # rpm --setugids -a 
  2.  
  3. # rpm --setperms -a 

當(dāng)再測(cè)試機(jī)上面執(zhí)行下面命令之后,所有文件權(quán)限都會(huì)變成777。

  1. [root@localhost ~]# chmod -R 777 / 

列出根目錄下面的內(nèi)容:

  1. [root@localhost ~]# ls -al / 

下面是SSH相關(guān)的重要文件,需要有正確的權(quán)限和所有權(quán)。但是,由于運(yùn)行chmod 777,以下所有文件都具有錯(cuò)誤的權(quán)限。

  1. [root@localhost ~]# ll /etc/ssh/ 
  2. total 588 
  3. -rwxrwxrwx. 1 root root     563386 May 11  2019 moduli 
  4. -rwxrwxrwx. 1 root root       1727 May 11  2019 ssh_config 
  5. drwxrwxrwx. 2 root root         28 Dec 29  2019 ssh_config.d 
  6. -rwxrwxrwx. 1 root root       4444 May 11  2019 sshd_config 
  7. -rwxrwxrwx. 1 root ssh_keys    480 Dec 29  2019 ssh_host_ecdsa_key 
  8. -rwxrwxrwx. 1 root root        162 Dec 29  2019 ssh_host_ecdsa_key.pub 
  9. -rwxrwxrwx. 1 root ssh_keys    387 Dec 29  2019 ssh_host_ed25519_key 
  10. -rwxrwxrwx. 1 root root         82 Dec 29  2019 ssh_host_ed25519_key.pub 
  11. -rwxrwxrwx. 1 root ssh_keys   1799 Dec 29  2019 ssh_host_rsa_key 
  12. -rwxrwxrwx. 1 root root        382 Dec 29  2019 ssh_host_rsa_key.pub 

帶有chmod 777權(quán)限的SSH

下面嘗試通過(guò)SSH遠(yuǎn)程登錄服務(wù)器。由于主機(jī)密鑰文件權(quán)限都變成了777了,所以登錄會(huì)被拒絕。

下面再終端中ssh登錄本機(jī)出現(xiàn)下面問(wèn)題:

下面使用Xshell登錄服務(wù)器,同樣不能登錄成功:

  1. [C:\~]$ ssh root@192.168.43.131 
  2.  
  3.  
  4. Connecting to 192.168.43.131:22... 
  5. Connection established. 
  6. To escape to local shell, press 'Ctrl+Alt+]'
  7. Connection closing...Socket close
  8.  
  9. Connection closed by foreign host. 
  10.  
  11. Disconnected from remote host(192.168.43.131:22) at 10:28:06. 
  12.  
  13. Type `help' to learn how to use Xshell prompt. 

恢復(fù)權(quán)限

需要恢復(fù)權(quán)限,我們需要加載Centos8的系統(tǒng)鏡像,開(kāi)機(jī)啟動(dòng)光盤(pán)鏡像:

在VMware Workstation中,加載光盤(pán),并開(kāi)機(jī)器用。開(kāi)機(jī)按F2,進(jìn)入BIOS,切換到Boot選項(xiàng)卡。將CD-ROM Drive移動(dòng)到Hard Drive上面。按F10保存并重啟。

選擇Troubleshooting,然后選擇進(jìn)入救援模式。

當(dāng)進(jìn)入下面界面時(shí),選擇1,直接進(jìn)入shell界面。

使用chroot命令將/mnt/sysroot切換為根目錄:

  1. sh-4.4#  chroot /mnt/sysroot 

使用以下兩個(gè)命令運(yùn)行,以恢復(fù)所有文件,目錄和配置的權(quán)限。運(yùn)行此命令時(shí),它將引發(fā)權(quán)限被拒絕錯(cuò)誤,并且無(wú)法訪問(wèn)錯(cuò)誤。只是忽略錯(cuò)誤。

  1. # rpm --setugids -a 
  2. # rpm --setperms -a 

參數(shù)說(shuō)明:

--setugids - 設(shè)置RPM包文件的用戶/組所有權(quán)。

--setperms - 設(shè)置RPM包文件的權(quán)限。

-a - 適用于所有已安裝的RPM軟件包。

完成操作之后,退出,并重啟:

  1. # exit 
  2.  
  3. # reboot 

查看權(quán)限、SSH連接服務(wù)器測(cè)試

下面登錄系統(tǒng)之后,看一下根目錄的權(quán)限是否恢復(fù)正常:

  1. # ls -l / 

運(yùn)行ssh登錄,發(fā)現(xiàn)不能登錄。使用netstat -tlunp發(fā)現(xiàn)ssh端口沒(méi)有監(jiān)聽(tīng)中,使用systemctl status sshd發(fā)現(xiàn)服務(wù)沒(méi)有啟動(dòng),啟動(dòng)sshd服務(wù)時(shí)發(fā)現(xiàn)不能啟動(dòng),下面查找原因:

發(fā)現(xiàn)密鑰文件的權(quán)限還是777,沒(méi)有還原:

下面設(shè)置密鑰文件權(quán)限:

  1. # chmod 644 /etc/ssh/ssh_config 
  2. # chmod 600 /etc/ssh/sshd_config 
  3. # chmod 640 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key 
  4. # chmod 644 /etc/ssh/ssh_host_rsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ed25519_key.pub 

下面再次啟動(dòng)sshd試一下:

  1. # systemctl enable sshd --now 
  2. # netstat -tlunp 

可以看到啟動(dòng)成功了。ssh遠(yuǎn)程登錄試一下,看到登錄成功了。

總 結(jié)

就這樣,我們已經(jīng)成功還原了已安裝的RPM軟件包的權(quán)限并恢復(fù)了服務(wù)器。切勿在任何文件系統(tǒng)或配置上使用chmod 777。

本文轉(zhuǎn)載自微信公眾號(hào)「Linux就該這么學(xué)」,可以通過(guò)以下二維碼關(guān)注。轉(zhuǎn)載本文請(qǐng)聯(lián)系Linux就該這么學(xué)公眾號(hào)。

 

責(zé)任編輯:武曉燕 來(lái)源: Linux就該這么學(xué)
相關(guān)推薦

2022-04-15 07:51:36

Centos8遷移邏輯卷

2019-10-28 14:38:36

RsyslogCentOS8開(kāi)源

2021-05-19 07:59:35

VDO存儲(chǔ)Centos8

2020-12-09 08:04:27

Centos8root密碼

2016-11-23 18:52:04

根目錄日志代碼

2021-05-18 19:20:26

CentOS8團(tuán)隊(duì)CentOS 10

2022-04-30 09:41:14

LinuxNTP服務(wù)器

2021-11-01 20:17:07

Go項(xiàng)目目錄

2016-11-21 21:28:51

根目錄日志代碼

2022-07-19 07:41:09

Centos8操作系統(tǒng)Nginx進(jìn)程

2018-03-26 13:45:27

LinuxWeb服務(wù)器文件權(quán)限

2019-10-14 15:00:12

Centos 8 RHEL 8VNC

2022-02-21 08:31:49

Centos8Caddy Web服務(wù)器

2021-04-14 09:53:00

Ubuntu權(quán)限命令

2019-09-27 08:52:12

RHELCentOSElastic sta

2021-11-16 08:04:05

Centos8擴(kuò)展名文件

2021-07-07 07:09:51

Centos8 RescueSSH

2010-04-09 10:08:22

Unix操作系統(tǒng)

2021-09-03 09:09:11

CentOS 8LinuxCloudLinux

2019-12-02 15:45:53

CentOS 8AnsibleLinux
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)