Tag Info

Hot answers tagged

143

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


77

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


55

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


53

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


53

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


33

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>


33

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

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.


21

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:   


19

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


16

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


16

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

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


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


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

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)


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

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

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

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


11

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


11

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


10

Why do you need octal number in the first place? I always use: chmod o+x file # all + eXecute permissions chmod g-w file # group - write perms chmod u=r file # user can just read chmod ug=rw file # user,group = read and write chmod a+w file # user,group,others + write ugo(a) is easy to remember. However you can confuse o:=owner? o:=other? but ...


10

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


10

You can ask GNU stat to output the permissions in octal format by using the -c option. From man stat: -c --format=FORMAT use the specified FORMAT instead of the default; output a newline after each use of FORMAT ⋮ %a access rights in octal ⋮ %n file name So in your case: bash-4.2$ ls -l foo ...



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