We're an ISO27001:2013 Certified Supplier


A discussion in the office at Tiger HQ recently made us wonder: how would different sorts of administrators tackle an unusual problem?

The problem

Hypothetical problems like this one are often brought out in classroom or interview scenarios:

“Somebody has removed the execute permission (x) from the chmod command [which manages permissions, so catch-22]. How can you restore the permission without resorting to reinstalling?”

The obvious answer is to reinstall the package providing chmod, but that’s not really in the spirit of the game. We collected quite a number of alternatives which would work and give an insight into how different system administrators think about problems like this one.

The file-server admin

If it’s installed (or can be), setfacl from the acl package can usually set things right:

setfacl -m u::rwx,g::rx,o::rx /bin/chmod

It’s normally used for setting extended ACLs for more complex access rights, but a simple incantation works in this scenario too.

The package maintainer

Package maintainers in distributions are well-used to using the install command to set up trees of files for later release. It can’t change an existing file, but that’s easily sorted:

cp /bin/chmod /var/tmp/chmod
install /var/tmp/chmod /bin/
rm /var/tmp/chmod

The default permission set by install is rwxr-xr-x or 0755, which is exactly we want – that can be changed with the -m switch if necessary.

The Perl monk

Perl has a chmod built-in:

perl -e 'chmod 0755, "/bin/chmod";'

This doesn’t call the chmod system binary, but rather the chmod(3) function in libc which in turn calls the chmod(2) system call in the kernel.

The C programmer

A short C program to fix this might look like:

#include <sys/stat.h>
int main() {
    chmod("/bin/chmod", 0755);

This assumes you have a compiler to hand of course, which you might not on a production system – there are differing views about how wise the ability to compile arbitrary code on a live system may be.

The escape artist

If none of these work, and booting the system into a rescue environment is not an option, there’s always busybox:

ln -s /bin/busybox /var/tmp/chmod
/var/tmp/chmod +x /bin/chmod
rm /var/tmp/chmod


Photo by Mat Reding on Unsplash

Get free Linux business strategies

Fill in this form and we'll send you updated Linux business strategies and ideas each week
  • This field is for validation purposes and should be left unchanged.