bash 我愚蠢地运行了“chmod 400 chmod”,现在它似乎永远坏了
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19554943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I stupidly ran "chmod 400 chmod" and now it appears forever broken
提问by Robert Caldwell
I'm "hacking" an ARM-base quadcopter running a stripped down Linux as part of a class assignment, and after getting into it using telnet and getting access to the bash terminal, and then messing around the file system I wanted to see what commands were available and how I could mess with it. I ran "chmod 400 chmod" and now I can't change it back, as when I run "chmod 777 chmod" I get "Permission Denied". Is there a command line fix for this? Or do I need some kind of factory reset to get chmod back? And yes I realized how stupid I am for having done this. Thanks!
作为课堂作业的一部分,我正在“破解”一个运行精简 Linux 的基于 ARM 的四轴飞行器,在使用 telnet 进入它并访问 bash 终端之后,然后在文件系统中乱搞,我想看看命令可用以及我如何处理它。我运行了“chmod 400 chmod”,现在我无法将它改回来,因为当我运行“chmod 777 chmod”时,我得到“权限被拒绝”。是否有针对此的命令行修复?或者我是否需要某种出厂重置才能恢复 chmod?是的,我意识到我这样做是多么愚蠢。谢谢!
回答by Barmar
If you have perl
, you can do:
如果你有perl
,你可以这样做:
perl -e 'chmod(0755, "chmod")'
回答by Brandon Haston
As suggested here: https://unix.stackexchange.com/questions/77852/how-to-recover-from-a-chmod-r-000-binyou could try using sudo perl -e 'chmod 0755, "/bin/chmod"'
to fix the permissions on the file.
正如此处所建议的:https: //unix.stackexchange.com/questions/77852/how-to-recover-from-a-chmod-r-000-bin您可以尝试使用sudo perl -e 'chmod 0755, "/bin/chmod"'
来修复文件的权限。
I tried this myself just now by copying /bin/chmod to ~/chmod, running ~/chmod 400 ~/chmod
then attempting to use ~/chmod again. I received a permission denied error as expected. I then used the perl trick such that perl -e 'chmod 0755, "~/chmod"'
and was able to once again use ~/chmod.
我刚刚通过将 /bin/chmod 复制到 ~/chmod,运行~/chmod 400 ~/chmod
然后再次尝试使用 ~/chmod 来尝试自己。我按预期收到了权限被拒绝的错误。然后我使用了 perl 技巧,perl -e 'chmod 0755, "~/chmod"'
并且能够再次使用 ~/chmod。
I hope this helps.
我希望这有帮助。
回答by Biluxx
Maybe it's possible to copy another chmod
binary (with executable rights) to the messed Linux and with that chmod
the messed up chmod
binary. eg
也许可以将另一个chmod
二进制文件(具有可执行权限)复制到混乱的 Linux 中,然后将其复制到chmod
混乱的chmod
二进制文件中。例如
/path/to/the/copied/chmod 777 /path/to/the/old/chmod.