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

相关推荐

  • 分区管理和文件系统

    管理分区:        lsblk           列出块设备        fdisk          创建MBR 分区      &nbs…

    Linux干货 2017-03-11
  • Linux shell脚本编程练习题

    《书籍上面的练习题》 问题:谁在霸占磁盘资源?     如果您负责的Linux服务器上有许多用户,则经常需要解决的一个问题就是谁在使用所有磁盘空间。这是个老掉牙的问题有时比其他问题更难以弄清。     不幸的是,虽然跟踪用户磁盘空间使用情况非常重要,但却没有一个Linux命令可以提供此信息。因此需要…

    Linux干货 2016-06-09
  • 硬盘基础知识及 MBR、GPT分区格式

    一,硬盘知识     硬盘接口类型:          并行:             IDE: 133MB/s &n…

    Linux干货 2016-09-19
  • Git 分布式 Moosefs + Corosync + DRBD 集群

        对于 Git 集群来说,在不采用存储阵列的情况下,分布式存储系统是一个很好的解决方案。目前可使用的分布式文件系统,初步了解了一下,Git 是属于小文件的应用,因此可考量的我想就只有目前的 Moosefs、Ceph 了,Ceph 目前好似国内应用不多,貌似不太稳定。至于 GlusterFS 其比较适用于大文件的应…

    Linux干货 2016-02-22
  • Linux的哲学思想

    初学Linux,了解一下Linux的哲学思想,对学习Linux还是非常有帮助的。 在了解Linux的哲学思想之前,可以先考虑一下,现在我们所学的Linux系统到底是面向什么应用场景而研发和使用的?个人认为:面向企业,是一个服务器操作系统。其所关注的地方是:高性能、可靠性、易维护性。 基于上述方面的考虑,Linux系统在构建和设计的时候,遵循了如下的哲学思想进…

    Linux干货 2017-08-30
  • 系统自动化安装、selinux

    系统自动化安装 系统启动流程:bootloader–>kernel(initramfs)–>rootfs–>anaconda–>/sbin/init anaconda: 系统安装程序    tui: 基于图形库curses的文本配置窗口 &nbsp…

    Linux干货 2016-09-22