Restore 777 File Permission On Linux

Restore 777 File Permission On Linux
Written by Harshit ShrivastavaMay 2, 2020
2 min read
Linux Administration
13 VIEWS 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 13 VIEWS SHARE
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
13 VIEWS 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 13 VIEWS SHARE
Was this blog helpful?
You must be Logged in to comment
Code Block
Harshit Shrivastava
2 Blog Posts
0 Discussion Threads
Trending Categories
37
Software1
DevOps15
Frontend Development4
Backend Development2
Server Administration1
Linux Administration5
Data Center0
Sentry0
Terraform2
Ansible0
Docker3
Penetration Testing0
Kubernetes0
NGINX0
JenkinsX0
Jenkins2
SSL0
Ethical-Hacking1
Python0
NodeJs1
RedHat0
Github0
AngularJs0
Google Cloud Platform (GCP)0
SonarQube0
Amazon Web Service (AWS)0
VMware0
Blockchain0
Snipe-IT1
MongoDB0