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.178linux.com/65504

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

相关推荐

  • Python线程指南

    本文介绍了Python对于线程的支持,包括“学会”多线程编程需要掌握的基础以及Python两个线程标准库的完整介绍及使用示例。 注意:本文基于Python2.4完成,;如果看到不明白的词汇请记得百度谷歌或维基,whatever。 尊重作者的劳动,转载请注明作者及原文地址 >.< 1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如…

    2015-03-13
  • select循环解析

    前言:   select命令用于创建菜单,在select循环执行时会根据list数组给出选择菜单,用户选择后的结果保存在变量中,然后给出菜单,等待用户选择。select是个死循环,如果用户用户想跳出选择循环,需要在循环体中根据条件增加break语句。 格式: select variable in list do 循环体命令 done 示例: 在这个…

    Linux干货 2016-08-24
  • Linux基础 sed命令详解

    概述 sed是一个流编辑器(Stream EDitor)。主要用于自动编辑一个或多个文件;简化对文件的反复操作;编写转换程序等。本文主要讲述了: sed工作原理 sed命令格式及常用选项 应用实例 高级编辑命令 sed工作原理 sed命令运行过程中维护着两个缓冲区,一个是活动的“模式空间(pattern space)”,另一个是起辅助作用的“暂存缓冲区(ho…

    Linux干货 2016-08-12
  • DNS and BIND 初步

    DNS and bind 初步 前言 TCP/IP协议通信是针对于ip地址的,你说我要是去淘宝买东西,怎么可能记住ip地址,我要是去百度买东西,也记不住啊,所以针对于此,就出现了这样一个翻译器,起一个名字,跟ip地址对应。是多对一还是一对多呢,都可以,我几个ip指向一个网址也没问题,几个网址指向一个ip也可以。 对于反向域名解析功能等以后用到再做总结,反向域…

    Linux干货 2016-12-06
  • Linux系统管理常用命令

    系统管理工具 进程的分类: CPU-Bound:CPU密集型,非交互。特别消耗CPU的,加密解密,压缩解压 IO-Bound:IO密集型,交互。大量的硬盘读写,例如复制文件 Linux系统状态的查看及管理工具:pstree, ps, pidof, pgrep, top, htop, glance, pmap, vmstat, dstat, kill, pki…

    Linux干货 2017-12-18
  • http://www.jianshu.com/p/aac6076e4ca2

    Linux干货 2017-07-29