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
下一篇 2017-01-02

相關推薦

  • nginx

    1.Nginx的程序架構:        master/worker            一個master進程:     &nb…

    2017-06-19
  • 使用tar打包并使用gzip壓縮的shell腳本應用實驗

    博客目的: 練習find,gzip,tar,grep,vim等命令的使用以及shell腳本的初步使用 命令行模式下: 1、find出/目錄下100M以上的文件并且查看 [root@rookie ~]# find / -size +100M | xargs ls -lh -r——–. 1 root root 128T 4月 8 16:02 /proc…

    Linux干貨 2017-04-09
  • MHA+keepalived 高可用MYSQL集群

    一、MHA簡介 二、試驗環境及要求 三、部署MHA 四、測試MHA集群功能 一、MHA簡介     MHA(Master High Availability)目前在MySQL高可用方面是一個相對成熟的解決方案。在MySQL故障切換過程中,MHA能做到在0~30秒之內手動或自動(結合腳本)完成數據庫的故障切換操作,并且在…

    2017-02-25
  • iptables練習

    iptables實戰 1.開啟防火墻 systemctl start firewalld 2.清空所有的默認規則,定義自己的規則 iptables -F 查看此時的iptables iptables -nL Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD…

    2015-03-15
  • Linux-Basic—shell如何解釋命令的運行

    附件下載: Linux Basics-shell.pdf

    Linux干貨 2016-11-21
  • linux發展編年史

    1965年,Bell實驗室、MIT、GE(通用電氣公司)準備開發Multics系統    1969年,Ken Thompson(B->C語言)利用匯編語言開發了FIle Server System(Unics,即Unix的原型)     為游戲開發出最多…

    Linux干貨 2016-10-18
欧美性久久久久