Tag Info

Hot answers tagged

148

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


79

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, ...


57

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 ...


55

I'll answer your questions in three parts: file types, permissions, and use cases for the various forms of chmod. File types The first character in ls -l output represents the file type; d means it's a directory. It can't be set or unset, it depends on how the file was created. You can find the complete list of file types in the ls documentation; those ...


54

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 ...


40

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>


35

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 ...


30

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 ...


26

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 ...


22

This site provides an interactive way to see what permissions bits are set when various bits are set/unset. http://permissions-calculator.org/ The "calculator" looks like this:   


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.


22

I played with it and apparently, exec permissions do not imply read permissions. Binaries can be executable without being readable: $ echo 'int main(){ puts("hello world"); }' > hw.c $ make hw $ ./hw hello world $ chmod 111 hw $ ./hw hello world $ cat hw /bin/cat: hw: Permission denied I can't execute scripts though, unless they have both read and ...


21

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 ...


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 ...


17

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 ...


16

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


16

So, permissions in Linux are very important. I will try to make a short explanation. For pieces of a file mode Every Unix file has a set of permissions that determine whether you can read, write, or run the file. Running ls -l displays the permissions. Here’s an example of such a display: -rw-r--r-- 1 user somegroup 7041 Mar 26 19:34 somefile I attach a ...


15

it make sense for directories, for example if you keep (secret) executables in a specific directory and then allow users call those files without being able to see the directory content (but knowing that a specific file is there after you informed them!). 333 compared to 111 allows writing/deleting files to/from those directories without being able to see ...


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

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)


14

Some systems have commands to display the permissions of a file as a number, but unfortunately, nothing portable. zsh has a stat (aka zstat) builtin in the stat module: zmodload zsh/stat stat -H s some-file Then, the mode is in $s[mode] but is the mode, that is type + perms. If you want the permissions expressed in octal, you need: perms=$(([##8] ...


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

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.


12

r=4 w=2 x=1 in every group. Your example is 6(r+w=4+2)4(r=4)4(r=4).


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 ...


12

First of all you have to know that the default permission of directories in Ubuntu is 644 which means you can't create a file in a directory you are not the owner. you are trying as user:francisco-vergara to create a file in a directory /home/sixven/camp_sms/inputs which is owned by user:sixven. So how to solve this: 1-You can either change the permission ...


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

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 ...



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