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

相关推荐

  • iptables/netfilter进阶

      在上一章当中我们介绍了iptables的介绍以及它的基本使用,下面我们开始介绍iptables的命令用法以及iptables是如何工作的。 1、回顾 2、iptables相关命令 1、回顾   我们回顾一下上一章节的内容,在上一章节中我们讲述的是iptables的基本概念以及命令格式,同时讲述规则链与表的概念,那么…

    Linux干货 2017-02-03
  • 修改文件的权限

        linux中一切皆文件,文件有权限,所有者,所属组,大小等属性。文件所有者是指创建文件的用户,所属组是指创建文件的用户属于哪一个主要的组(用户的主组只能有一个)。     用户对文件进行各种操作的前提是有相应的权限,所以有些文件我们只能读,不能写,而有些文件既可以读写,还可以更改内容,下面就…

    2017-07-30
  • N25第二周作业

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。     其常用的有: touch、stat、rm、cp、mv、install touch 命令    命令格式: touch [OPTION]… File… 命令参数: -a&n…

    Linux干货 2016-12-12
  • RAID磁盘冗余探究

    RAID磁盘冗余探究 RAID的全称是Redundant Arrays of Inexpensive Disk,可以翻译为廉价的磁盘冗余阵列。由加利福尼亚大学伯克利分校的一位教授在1988年提出,是一种磁盘管理方式。其产生的初衷是为了降低成本,但是为了达到RAID的功能,其造价并不便宜,所以后来改为Redundant Arrays of Independen…

    2017-08-26
  • 震惊!!iptables还能这样用!

    基本语法:iptables [-t 表] [操作命令] [链][规则匹配器][-j 目标动作] 系统的INPUT和OUTPUT默认策略为DROP; # iptables -P INPUT DROP # iptables -P OUTPUT DROP 1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin…

    系统运维 2017-04-18
  • Centos6搭建vsftpd手册

    1、开启防火墙ftp端口vi /etc/sysconfig/iptables     #编辑防火墙配置文件 1 -A INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT(允许21端口通过防火墙) 2 -A INPUT -m st…

    Linux干货 2017-04-26