Restore 777 File Permission On Linux

Restore 777 File Permission On Linux
Techiio-author
Written by Harshit ShrivastavaMay 2, 2020
2 min read
Linux Administration
16 VIEWS 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 16 VIEWS SHARE
Techiio-author
Harshit Shrivastava

This Blog will guide you to reset the file permissions on Linux.

Often permissions are lost on accidentally running the command on Linux System (RPM- Based),

1. Centos

2. SLES

3. Fedora

This blog will guide you to restore the permissions back to the original state.

Let’s begin the fun !!!

1. Type the below command on your test VM

#chmod -R 777 /


2. Now check the permission for / file system.

blogpost


Issues:

User may encounter the following issues on running #chmod 777 / command:

1. SSH Service will not start as shown in the below screenshot:

blogpost

2. Users wont be able to switch accounts even after having root privileges.
3. Users would not be able to login via SSH.
4. SUID will be revoked from the files and binaries.

Solution:

Run the below two commands to restore the permissions of all files and directories. Ignore the permission denied error and can’t access error, which may occur while running the below command.

#rpm --setugids -a  
#rpm --setperms -a


The options used here are --setugids, --setperms and -a
--setperms – sets permissions of files in the given package.
--setugids – user/group ownership of files in the given package.
-a – While we using -a or –all it applied for all installed RPM packages.

Refer man page using below command:

#man rpm


To reset permission on the whole / directory, one can use the following commands:

#for package in $(rpm -qa); do rpm --setperms $package; done  

blogpost

#for package in $(rpm -qa); do rpm --setugids $package; done

blogpost

Reason:

The RPM package installed in the system creates its own RPM database which holds the information such as file sizes, md5sums of files, ownership, permissions, and more. Hence this is the reason a user can restore the file ownership and permissions.

Important points:

  1. It is not possible to fix File Ownerships and Permissions that are unknown to RPM.
  2. File Ownerships and Permissions cannot be restored on Deb based system. For example Debian, Ubuntu, Linuxmint, etc.
CentOS
Linux
16 VIEWS 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 16 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance