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

相关推荐

  • CentOS7下利用rsyslog+loganalyzer配置日志服务器及Linux和windows客户端配置

    随着机房内的服务器和网络设备增加,日志管理和查询就成了让系统管理员头疼的事。 系统管理员遇到的常见问题如下: 1、日常维护过程中不可能登录到每一台服务器和设备上去查看日志; 2、网络设备上的存储空间有限,不可能存储日期太长的日志,而系统出现问题又有可能是很久以前发生的某些操作造成的; 3、在某些非法入侵的情况下,入侵者一般都会清除本地日志…

    2017-03-15
  • 正则表达式详解

    正则表达式详解

    2017-09-20
  • 创建目录树

    创建目录树 [wing@bogon ~]$ mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,\ sysconfig/network-scripts},\ lib/modules,lib64,proc,sbin,sys,tmp,usr/local{bin,sbin},\ var/{lock,…

    Linux干货 2017-07-24
  • 管理systemd

    管理systemd 一、systemd介绍 回顾一下centos的启动流程  POST –> Boot Sequence –> Bootloader –> kernel + initramfs(initrd) –> rootfs –> /sbin/init 在…

    Linux干货 2016-09-22
  • btrfs文件系统常用命令使用

    Btrfs,也可称为B-tree,Butter FS,Better FS,是CentOS7中一种新型的文件系统。 核心特性: 1.多物理卷支持,可由多个物理卷(pv)组成,支持raid,以联机添加删除 2.支持写实复制(Copy on Write,Cow) 复制一份修改,改好之后用指针替换,出错时指回原本文件。而不是就地修改 3.数据及元数据校验码:chec…

    Linux干货 2016-03-07
  • Openssl搭建私有CA认证

    概述 CA英文全称Certification Authority,即数字证书认机构。从广义上来说,CA是负责发放和管理数字证书的权威机构,并作为用户数字认证中受信任的第三方,承担公钥体系(PKI)中公钥的合法性检验的责任,在互联网上,实现用户与用户、用户与企业之间的数字身份认证。 本文通过使用openssl进行搭建私有CA认证体系,从而简单地了解CA的认证过…

    Linux干货 2016-09-22