Categories: TutorialsUbuntu

How to Protect Hard and Symbolic Links in CentOS

Every Linux system allows you to create hard and symbolic (soft) links to files, applications and directories. Hard links are actual copies of the file or directory whereas symbolic links are simply pointers to the original file or directory. It is important to prevent these links from being deleted otherwise important files & directories on your system may stop working properly. Also, it allows malicious software from deleting or modifying links on your system, to suite their requirements and damage your data/system. But did you know you could protect these links from being deleted? In this article, we will learn how to protect hard and symbolic links in CentOS.

How
Sponsored
to Protect Hard and Symbolic Links in CentOS

Here are the steps to protect hard and symbolic links in CentOS. Luckily, there exist certain security features in RHEL/CentOS systems that protect links from being created or pointed to.

For example, a user can create hard links only to files & directories that he/she owns. Alternatively, the user must have read/write access to the file/directory that they want to link to.

In case of soft links, processes are allowed to link to symbolic links if they are the owner of the symbolic link or the directory containing the symbolic link.

Enable or Disable Protection of Hard/Symbolic Links

By default, this feature is enabled in configuration file at /usr/lib/sysctl.d/50-default.conf. If you open this file in text editor, you will see the following values.

fs.protected_hardlinks = 1
fs.protected_symlinks = 1

If you want to modify this setting, you can set the above flags to 0. Alternatively, create another new file with the following filename. You need to use a filename such that it is read only after reading the default file mentioned above.501-noprotect-links will be read after 50-default.conf since all files in this directory are read alphabetically one after the other.

$ vi /etc/sysctl.d/51-noprotect-links.conf

Add the following lines to it.

Sponsored
fs.protected_hardlinks = 0
fs.protected_symlinks = 0

Save and close the file. Run the following command to apply changes.

# sysctl --system
OR
# sysctl -p  #on older systems

In this article, we have learnt how to protect hard and symbolic links in CentOS. The key is to set the required flag to 1 or 0 depending on whether you want to enable/disable protection.

Please note, the above changes will be applicable to all hard or symbolic links on your system. It will not allow you to selectively protect only certain links on your system.

Also read:

How to Run Shell Script on Another Server
How to Manage Systemd Services on Remote Linux Systems
How to Synchronize Time with NTP in Linux
How to Enable Confirmation for Rm Command
How to Share Linux Terminal Session

The post How to Protect Hard and Symbolic Links in CentOS appeared first on Fedingo.

Ubuntu Server Admin

Recent Posts

Ubuntu 25.10 Beta Release is Available to Download

Ubuntu 25.10, code-name Questing Quokka, is now available for Beta testing! The developer team announced…

2 days ago

How to build an awesome cloud gaming platform with Anbox Cloud

Why cloud gaming? Cloud gaming is changing the way we play. Instead of buying expensive…

2 days ago

Dolphin Emulator 2509 now Emulates Cars 2 & Disney Infinity Smoothly

Dolphin, the free open-source GameCube and Wii game emulator, released new 2509 version today after…

3 days ago

GNOME 49 Officially Released with New Video Player & Document Viewer

GNOME developer team finally announced the 49 release of this popular Linux Desktop environment! If…

3 days ago

Ubuntu 25.10 (Questing Quokka) Beta released

The Ubuntu Release team is pleased to announce the Beta release of the Ubuntu 25.10…

3 days ago

Canonical achieves IEC 62443-4-1 compliance in Industrial Automation and Control Systems

Canonical is proud to announce it has achieved compliance with IEC 62443-4-1 for cybersecurity in…

3 days ago