Do Not Allow Broken Symbolic Links
Broken symbolic links are redundant files, and they consume system resources and pose potential security risks. If a file with the same name and path is later created at the target location while the old symlink remains uncleaned, attackers might exploit the symlink to access the target file, leading to unauthorized information disclosure or file tampering. Once its target file is deleted, a symbolic link serves no purpose and must be removed to ensure no broken symbolic links exist in the system.
Procedure
- Run the find command to search for broken symbolic links globally or within a specified directory. The following is an example.
find ./ -type l -follow
If the command returns no output, no broken symbolic links are found. Otherwise, the name of a broken symbolic link will be returned (such as ./testlink in this example output)
./testlink
- To exclude some directories from the search (such as /proc, /run, /var, /sys, and /dev), use the following command. This will identify /root/testlink as a broken symbolic link while skipping the excluded system directories.
find / -path /var -prune -o -path /run -prune -o -path /proc -prune -o -path /sys -prune -o -path /dev -prune -o -type l -follow
/dev /proc /root /testlink /run /var /sys
- Alternatively, use the -xdev option to restrict the search to the filesystem of the current partition, skipping other mounted partitions.
find / -xdev -type l -follow
- To exclude some directories from the search (such as /proc, /run, /var, /sys, and /dev), use the following command. This will identify /root/testlink as a broken symbolic link while skipping the excluded system directories.
- If any broken symbolic links are found, run the rm command to remove them.
rm ./testlink
Parent topic: Manual Configuration Items