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

相关推荐

  • 马哥教育网络班22期+第11周课程练习

    1、详细描述一次加密通讯的过程,结合图示最佳。 Bob先利用单向加密算法提取当前数据的指纹(特征码),再用自己的私钥加密数据指纹并附加于数据尾部, 然后利用对称加密将整个文件加密,之后用Alice的公钥加密对称加密密钥附加于尾部。 Alice收到数据后,先用自己的私钥解密,得到对称加密密钥,之后用对称加密密钥解密,然后用Bob的公钥 解密得到数据指纹,并且验…

    Linux干货 2016-11-14
  • LVM(逻辑卷)(logical volume manager),快照卷

    逻辑卷的创建,扩展,缩减,迁移,删除。快照卷的创建

    Linux干货 2017-12-11
  • 生产环境模拟实现keepalived+Nginx调度器+httpd的高可用集群

    具体过程是用Nginx做负载均衡,可以将Nginx和主机放在同一台机子上,也可以分开放置,只不过分开的话要指明RS是Nginx的主机地址。至于直接将虚拟地址配置在Nginx主机上我暂时还未成功 下面附上我的双主模型的主keepalived服务器的配置 ! Configuration File for keepalive…

    Linux干货 2016-11-11
  • 马哥M20-1第一周作业

    作业1:通过echo实现字体闪烁,添加下划线,改变颜色      (1)添加下划线    (2)字体闪烁   (3)改变颜色 作业2:显示前10天的年月日 作业3:screen的使用

    Linux干货 2016-07-29
  • Mysql备份II

    Mysql备份II V.II.I单台或共用机器,数据量和访问量小50G< 1 Mysqldump(全导出,导库,导表) 锁表 如果这时有些入会锁住或者超时 2 至少停止写入 防止innodb配置还没刷到磁盘里 先flash tables /usr/local/mysql/bin/mysqladmin -S /tmp/mysql.so…

    Linux干货 2016-06-09
  • ☞{ 编译内核;自制linux; }

    编译内核、自制linux 自制简单的linux 前提约定 CentOS 6.8 , Kernel-2.6.32-642.el6.x86_64 基于GRUB – 0.97 / 分区与 boot 分区独立, /boot 分区 100M+ ,/ 根分区看具体需求,此处为 1G Vmware 12.1,新建一个Li…

    Linux干货 2016-09-15