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

相关推荐

  • 在Centos7上源码编译httpd

    在Centos7上源码编译httpd 安装源码包 首先在http://httpd.apache.org下载所需要的安装包 小编在这里下载的是httpd-2.4.27.tar apr-1.6.2.tar apr-util-1.6.0.tar 首先编译安装apr-1.6.2.tar.gz #1 tar -zxf apr-1.6.2.tar.gz #先解压安装包 …

    2017-08-21
  • find 和 压缩工具

    find命令 一、find命令基本介绍 1、find作用 通过遍历指定路径实时查找符合条件的文件。 find工作特点 2、find工作特点 查找速度较慢 精确查找 实时查找 用户只能搜索有读取和执行权限的目录 3、语法 find [OPTIONS]… [查找路径] [查找条件] [处理方式] 查找路径:指定…

    Linux干货 2016-08-16
  • N25-第二周做业

    一.Linux上的文件管理类命令都有哪些,其常用的使用方法和演示        1.目录管理的命令    mkdir rmdir              1)…

    Linux干货 2016-12-11
  • systemd和systemctl

    systemd:      POTS–>boot Sequence(BIOS)–>Bootloader(MBR)–>kernel(ramdisk)–>rootfs(swithroot)–>/sbin/init    &n…

    Linux干货 2016-09-22
  • 系统基础之vim工具详解

    vim工具详解 作为运维人员,每天要面对大量的文件操作,如何使用一个功能强大,操作快捷的文本编辑器,就至关重要.那天,今天给大家详细的介绍下vim这款编辑器,完全符合我们的要求,下面让我们一起来看看吧! 概论:  文本编辑器:  文本:纯文本信息,   ASCII text:  纯粹的,不加修饰的文字  文本…

    Linux干货 2016-08-10
  • 四.Linux博客-2016年7月26日ls、通配符、touch、cp、mv、rm、mkdir

    格式说明: 操作 概念 命令 说明及举例 四.ls、通配符、touch、cp、mv、rm、mkdir du -sh /sys 查看文件、文件夹大小 /sys/class/scsi_host/host2/scan 在线扫盘(新加硬盘执行这个命令后才能发现) stat /etc/issue 更详细的看数…

    Linux干货 2016-08-23