Рубрики
Bash Linux

Restore executable permission to Chmod command in Linux

Problem: chmod command not executable anymore.

chmod -x $(which chmod)

# result
chmod +x $(which chmod)
bash: /usr/bin/chmod: Permission denied

Solution №1
Copy the contents of the chmod binary to other working binaries

# Backup original executable file
cp /usr/bin/mkdir /usr/bin/mkdir.bak

# Copy contents of chmod command to mkdir
cat /usr/bin/chmod > /usr/bin/mkdir

# Set executable permissions with "new" chmod file
mkdir +x /usr/bin/chmod

# Restore original chmod name
mv /usr/bin/mkdir /usr/bin/chmod

# Restore original mkdir file
mv /usr/bin/mkdir.bak /usr/bin/mkdir

# Check if restored chmod is executable now
ls -lah $(which chmod)

Solution №2
Using the cp command with only attributes parameter

cp --attributes-only --preserve=mode /proc/self/exe /usr/bin/chmod

Solution №3
Use setfacl command

setfacl -m u::rx /usr/bin/chmod

# If command setfact not found install packet
apt install acl

Solution №3
Using rsync

rsync /usr/bin/chmod /tmp/chmod --chmod=ugo+x

mv /tmp/chmod /usr/bin

Solution №4
Using Busybox

busybox chmod +x /usr/bin/chmod

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.