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
93
Software12
DevOps34
Frontend Development13
Backend Development13
Server Administration13
Linux Administration12
Data Center14
Sentry11
Terraform15
Ansible9
Docker13
Penetration Testing12
Kubernetes12
NGINX8
JenkinsX10
Jenkins18
SSL6
Ethical-Hacking10
Python8
NodeJs9
RedHat8
Github11
AngularJs15
Google Cloud Platform (GCP)6
SonarQube9
Amazon Web Service (AWS)2
VMware17
Blockchain6
Snipe-IT7