chmod 沒有執行權限的解決辦法 [轉載http://www.fblinux.com/?p=30]

chmod沒有權限,貌似就算是root用戶也無法授權,這可咋辦?chmod是設置權限的命令,但是自身沒有了執行權限,那么就表示沒有辦法更改其他命令的權限,也沒有辦法改變自己的權限。

1
2
3
4
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 Oct 15 2014 /bin/chmod
[root@localhost ~]# chmod 755 /bin/chmod
-bash/bin/chmod: Permission denied

解決方法1:

直接運行加載程序,并將其傳遞給想要運行的命令

1
2
3
[root@localhost ~]# /lib64/ld-linux-x86-64.so.2 /bin/chmod 755 /bin/chmod
[root@localhost ~]# ll /bin/chmod
-rwxr-xr-x. 1 root root 48712 Oct 15 2014 /bin/chmod

加載程序路徑可能不同,32位系統應該是/lib/ld-linux.so,我沒有測試

解決方法2:

可以使用busybox的chmod授權

1
2
3
[root@localhost ~]# busybox chmod 755 /bin/chmod
[root@localhost ~]# ll /bin/chmod
-rwxr-xr-x. 1 root root 48712 Oct 15 2014 /bin/chmod

解決方法3:

此方法我表示很喜歡

1
2
3
4
5
6
7
8
9
[root@localhost ~]# chmod 000 /bin/chmod
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 Oct 15  2014 /bin/chmod
[root@localhost ~]# mv /bin/chmod /bin/chmod.orig
[root@localhost ~]# cp -a /bin/chown /bin/chmod
[root@localhost ~]# dd if=/bin/chmod.orig of=/bin/chmod
95+1 records in
95+1 records out
48712 bytes (49 kB) copied, 0.00117323 s, 41.5 MB/s

解決方法4:

使用facl額外授權

1
2
3
4
5
6
[root@localhost ~]# chmod 000 /bin/chmod
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 Oct 15 2014 /bin/chmod
[root@localhost ~]# setfacl -m u::rx /bin/chmod
[root@localhost ~]# chmod 755 /bin/chmod
[root@localhost ~]# setfacl -b /bin/chmod

解決方法5:

復制一個可執行文件,然后使用chmod命令覆蓋

1
2
3
4
5
6
7
8
9
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 Oct 15  2014 /bin/chmod
[root@localhost ~]# cp /bin/ls chmod
[root@localhost ~]# cp /bin/chmod .
cp: overwrite `./chmod'? y
[root@localhost ~]# cp -a chmod /bin/chmod
cp: overwrite `/bin/chmod'? y
[root@localhost ~]# ll /bin/chmod
-rwxr-xr-x. 1 root root 48712 May 27 10:23 /bin/chmod

解決方法6:

使用install命令的-m選項也可以設置權限

1
2
3
4
5
6
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 May 27 10:04 /bin/chmod
[root@localhost ~]# install -m a+x /bin/chmod .
[root@localhost ~]# ./chmod 755 /bin/chmod
[root@localhost ~]# ll /bin/chmod
-rwxr-xr-x. 1 root root 48712 May 27 10:04 /bin/chmod

解決方法7:

perl解決

1
2
3
4
5
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 Oct 15 2014 /bin/chmod
[root@localhost ~]# perl -e 'chmod 0755, "/bin/chmod"'
[root@localhost ~]# ll /bin/chmod
-rwxr-xr-x. 1 root root 48712 Oct 15 2014 /bin/chmod

解決方法8:

Python解決

1
2
3
4
5
6
[root@localhost ~]# chmod 000 /bin/chmod
[root@localhost ~]# ll /bin/chmod
----------. 1 root root 48712 Oct 15 2014 /bin/chmod
[root@localhost ~]# python -c 'import os; os.chmod("/bin/chmod", 0755)'
[root@localhost ~]# ll /bin/chmod
-rwxr-xr-x. 1 root root 48712 Oct 15 2014 /bin/chmod

[轉載http://www.fblinux.com/?p=30]

原創文章,作者:不忘初衷,如若轉載,請注明出處:http://www.www58058.com/65504

(2)
不忘初衷不忘初衷
上一篇 2017-01-01 22:11
下一篇 2017-01-02 00:02

相關推薦

  • linux基礎知識

    馮*諾依曼體系 摩爾定律

    2018-03-26
  • GNU awk

    文本處理三工具:grep, sed, awk grep, egrep, fgrep:文本過濾工具;pattern sed: 行編輯器 模式空間、保持空間 awk:報告生成器,格式化文本輸出;  AWK: Aho, Weinberger, Kernighan –> New AWK, NAWK  GNU awk, gawk&…

    Linux干貨 2015-12-03
  • Bash Shell詳解

    引言:什么是Shell? Linux的命令行接口歸結起來就是各種Shell,那么到底什么是Shell?Shell,譯為外殼,是用戶直接連入計算機所使用的計算機程序,負責解析用戶提供的命令,如詞法分析、語法分析、句法分析。 1.Shell的分類 Linux 的命令 shell 是與操作系統相分離的一層。不同的 shell 環境影響您具備不同的功能,比如可編輯的…

    2017-09-07
  • 編譯內核制作小型的linux

    1.  前言       今天我將會給大家帶來如何定制一個屬于自己linux系統,也就是編譯內核,那為什么要編譯內核呢? 內核,是一個操作系統的核心。它負責管理系統的進程、內存、設備驅動程序、文件和網絡系統管理,決定著系統的性能和穩定性。Linux作為一個自由軟件,在廣 大愛好者的支持下,內核版本不…

    Linux干貨 2016-08-03
  • 初識正則表達式

    正則表達式是個什么東東? 正則表達式,又稱正規表示法、常規表示法(英語:Regular Expression,在代碼中常簡寫為regex、regexp或RE)。在很多文本編輯器里、命令中,通常要使用檢索、替換、放行和拒絕那些符合某個模式的文本。而正則表達式就是用于描述這些規則的工具。換句話說,正則表達式就是記錄文本規則的代碼。  摘自《正則表達式之…

    Linux干貨 2015-03-27
  • Linux之函數

      Linux之函數     函數介紹?函數function是由若干條shell命令組成的語句塊,實現代碼重用和模塊化編程。?它與shell程序形式上是相似的,不同的是它不是一個單獨的進程,不能獨立運行,而是shell程序的一部分。?函數和shell程序比較相似,區別在于:?Shell程序在子Shell中運行?而Shell函數在…

    Linux干貨 2016-08-25
欧美性久久久久