Tag Info

Hot answers tagged

140

You can run the loader directly, and pass it the command you want to run: /lib/ld-linux.so /bin/chmod +x /bin/chmod Your path to the loader might vary, and on a 64-bit system you need to choose the right one based on how chmod was compiled; the 64-bit version is named something like /lib/ld-linux-x86-64.so


75

The chmod utility relies on the chmod() system call (see man 2 chmod). So you could do this with a few lines of C, or just about any other language that has a wrapper around it (which would be most of them). Very few *nix systems are going to lack a C compiler and a perl interpreter; most linux distros require the later to work. perl -e 'chmod 0755, ...


52

Some systems also have busybox installed in which case you may run: busybox chmod +x /bin/chmod Since you were asking for hacks, I just thought of another one: mv /bin/chmod /bin/chmod.orig cp -a /bin/chown /bin/chmod Now you have a /bin/chmod that's executable but it's actually chown (i.e. some other binary). Now all we have to do is overwrite it with ...


51

Even as root, you can't execute files that have no x permission bit set. What you can do though is call ld.so on it: sudo /lib/*/ld*.so /bin/chmod 755 /bin /bin/chmod Or call something in /usr/bin or elsewhere to do the chmod like perl: sudo perl -e 'chmod 0755, "/bin", "/bin/chmod" Beware when restoring permissions that some files in /bin like mount ...


31

Easy. What you can do is prepare some other executable file, and then cp chmod over it. $ cp /bin/ls chmod $ cp /bin/chmod . The first cp creates a file called chmod with executable permissions, but which is really the ls executable. The second cp populates this file with the binary code of chmod, while preserving the execute permissions of the target ...


28

Using the octal codes has two advantages I can think of, neither of which is that huge: They're shorter, easier to type. A few things only understand them, and if you routinely use them you'll not be scratching your head (or running to documentation) when you run into one. E.g., you have to use octal for chmod in Perl or C. Sometimes really simple ...


24

Problems? Yes, lots. Can it be fixed? Sure. Faster than reinstalling? Probably not. My recommendation is to reinstall. Keep a backup of the existing system, and restore the package list and the contents of files in /etc and /var. For /usr/local, you can probably restore permissions manually. For /home and /srv, you'll have to restore the permissions from ...


23

You can get the value directly using a stat output format, e.g. BSD/OS X: stat -f "%OLp" <file> or in Linux stat --format '%a' <file>


22

Boot another clean OS, mount the file system and fix permissions. As your broken file system lives in a VM, you should have your host system available and working. Mount your broken file system there and fix it. In case of QEMU/KVM you can for example mount the file system using nbd.


19

It's the other way around. It will give rwx permission for others. touch samplefile ls -l samplefile -rw-rw-r-- 1 ramesh ramesh 0 Oct 16 22:29 samplefile Now after I execute the command, I get the output as, chmod 7 samplefile ls -l samplefile -------rwx 1 ramesh ramesh 0 Oct 16 22:29 samplefile From man page of chmod, numeric mode is from one to ...


19

Ramesh's answer is perfectly accurate, but I wanted to chime in and provide a more in depth explanation of file modes. While numbers like 755 and 777 may seem special and only mean something for file modes, they're actually pretty basic. These numbers are actually octal numbers. Decimal numbers are base-10, hex numbers are base-16, binary is base-2, and ...


18

http://permissions-calculator.org/


17

Please note that chmod 777 filename is the equivalent of chmod 0777 filename in this example. The first octal digit sets the setuid, setgid and sticky bits (see this article for more details on setuid/setgid). octal 2 means to set group ID on the file. So, the equivalent would be to do a chmod a+rwx filename, then chmod g+s filename. The chmod info page ...


14

There is -strictly speaking- no such thing in UNIX as "conflicting permissions": access permissions on an filesystem entry (directory, file, etc.) determine what you can or can not do on that object. Permissions on other filesystem entries do not enter into the picture, with the exception of the "x" bit on all ancestors directories in the path to a file ...


14

This is what you want: chmod -R g=u directory


13

You may not notice it at first, but lots of things can and will go wrong. The main problem is that the entire security model for the entire system is broken. It's like having a body without a skin, organs all out in the air. It's bound to get infected because it's not meant to function like that. Even if it seems to work for a few minutes, you need to clean ...


13

Make sure that your mount options allow the execute permission bit. There are mount options one can use to limit the permissions of files within the mounted filesystem: general noexec prevents all files from being executable, FAT-specific option showexec grants the permission only to files with extensions .exe, .com and .bat. Note also that noexec is ...


12

First things off the top of my head, Boot from any other source (network book, cd, etc.) and use the chmod on that source to set the permissions. Write a tiny C program to change the permissions. Write a perl script (ruby, php, python, etc.) to change the permissions /usr/bin/chmod is just making a system call to change the permissions, you can make that ...


11

You can use find. find ./ -type d -execdir chmod 750 {} + Where 750 is the mode you'd like to apply and "./" is the directory you will recursively search. EDIT: Thanks to @Gilles and find(1), I've revised this for additional security and performance.


11

There's no magic bullet here. The permissions carry information which is not always redundant. If you'd done this in a system directory, your system would be in a very bad state, because you'd have to worry about setuid and setgid bits, and about files that are not supposed to be world-readable, and about files that are supposed to be group- or ...


11

Please check stat output: # stat .xsession-errors File: ‘.xsession-errors’ Size: 839123 Blocks: 1648 IO Block: 4096 regular file Device: 816h/2070d Inode: 3539028 Links: 1 Access: (0600/-rw-------) Uid: ( 1000/ lik) Gid: ( 1000/ lik) Access: 2012-05-30 23:11:48.053999289 +0300 Modify: 2012-05-31 07:53:26.912690288 ...


11

You need :! chmod +x % The ! is used to run your commands in a shell.


10

Is using find or xargs mandatory? If not, you can use: chmod -R u=rwX,go=rX *


10

The permissions passed as an argument to chmod are specified as an octal value. Each numeral in the value represents three bits. If three numerals are given, you're setting the read, write and execute bits for the file's owner, group and others (everyone else). If four numerals are given, the leftmost number sets the setuid, setgid and sticky bits. Octal ...


10

TL;DR; NOTE: Based on the continuous updating of the question by the OP with new information it was determined that the issue was he was mounting a NTFS partition. So #3 below is the actual answer to his problem. I leave the other 2 methods here for others that may encounter similar issues that aren't using an NTFS partition. Idea #1 - media's readonly ...


9

Here's a script you can call by passing the mode as the first argument and one or more directory names as subsequent arguments. Under Linux, if you don't pass any directory name, it'll be as though you passed . (the current directory). Name this script rchmodf, make it executable (chmod a+rx /path/to/rchmodf) and put it somewhere on your $PATH. #!/bin/sh ...


9

You need to have the execute bit set on a directory to allow the affected user to enter it and access files and directories inside, and you've removed it (your command removes the execute bit from both the files and the folders). There is information about this here. The following command should fix it: find ~/Documents -type d -exec chmod a+x {} +


9

If you don't want to remove the executable bit from existing files you can use the X mode. To recursively set the executable bit on all directories use: chmod -R a+X dir From man chmod: execute/search only if the file is a directory or already has execute permission for some user (X)


9

from man chmod: 2000 (the setgid bit). Executable files with this bit set will run with effective gid set to the gid of the file owner.


9

Each number (also referred to as an octal because it is base8) in that grouping represents 3 bits. If you turn it into binary it makes it a lot easier. 1 = 0 0 1 3 = 0 1 1 5 = 1 0 1 7 = 1 1 1 So if you did 1777, 3777, 5777, or 7777 you would set the sticky bit because the third column would be a 1. However, with 3777, 5777, and 7777 you are ...



Only top voted, non community-wiki answers of a minimum length are eligible