Symbolic links and special permissions

5.4 Special Directories and Files (Weight: 1)

📘Linux Essentials (LPI 010-160)


1. Symbolic Links (Symlinks)

What is a Symbolic Link?

A symbolic link (also called a soft link or symlink) is a special type of file that points to another file or directory.

Instead of containing actual data, it contains a reference path to another file.

When a program or user accesses the symbolic link, the system redirects the access to the original file.

Key Characteristics

  • It is a separate file that points to another file.
  • It contains the path to the target file or directory.
  • If the target file is removed, the symbolic link becomes broken.
  • Symbolic links can point to:
    • Files
    • Directories
    • Files located on other filesystems.

Viewing Symbolic Links

You can identify symbolic links using the ls -l command.

Example:

ls -l

Output example:

lrwxrwxrwx 1 user user 12 Mar 10 10:00 config -> /etc/config

Explanation:

FieldMeaning
lFile type is symbolic link
rwxrwxrwxLink permissions
configName of link
->Points to
/etc/configTarget file

The first character l indicates a symbolic link.


Creating Symbolic Links

The command used is:

ln -s target link_name

Example:

ln -s /etc/nginx/nginx.conf nginx_config

Result:

  • nginx_config becomes a symbolic link.
  • It points to /etc/nginx/nginx.conf.

Removing Symbolic Links

Symbolic links are removed like normal files:

rm link_name

Example:

rm nginx_config

This removes only the link, not the original file.


Broken Symbolic Links

A symbolic link becomes broken when the target file does not exist.

Example situation:

ln -s /etc/app/config.conf config

If /etc/app/config.conf is deleted, the link config remains but does not work.

ls -l may display it like:

config -> /etc/app/config.conf

But accessing it will result in an error.


Symbolic Links in IT Environments

Symbolic links are widely used in system administration.

Configuration File Management

Example:

Applications may expect configuration files in /etc.

But the real configuration may be stored elsewhere.

Example:

/etc/app.conf -> /opt/app/config/app.conf

This allows:

  • applications to use /etc/app.conf
  • administrators to store configuration elsewhere.

Software Version Management

Example structure:

/opt/java/java17
/opt/java/java21

A symbolic link can be used:

/opt/java/current -> /opt/java/java21

Programs can always reference:

/opt/java/current

When upgrading, the administrator simply updates the symbolic link.


Shared Resources

Example:

A shared library stored in one location:

/usr/lib/libapp.so

Multiple programs may access it via symbolic links in different directories.


2. Special Permissions

Normally Linux permissions include:

  • Read (r)
  • Write (w)
  • Execute (x)

But Linux also supports three special permissions that modify normal permission behavior.

These are:

PermissionName
SUIDSet User ID
SGIDSet Group ID
Sticky BitRestricted deletion flag

These permissions are commonly used in multi-user systems.


3. SUID (Set User ID)

What is SUID?

The SUID permission allows a file to run with the permissions of the file owner, not the user executing it.

This is usually applied to executable programs.


Example Behavior

If a program is owned by root and has the SUID bit, then:

  • Any user running that program temporarily runs it with root privileges.

Example in Linux Systems

A well-known example is the passwd program.

/usr/bin/passwd

This program allows users to change their passwords.

The program needs to modify the file:

/etc/shadow

This file is normally only writable by root.

But users can still change passwords because passwd runs with SUID root permissions.


Viewing SUID Permissions

Use:

ls -l

Example:

-rwsr-xr-x 1 root root 54256 Mar 10 10:00 passwd

Notice:

rws

The s replaces the x in the owner’s permission.

Meaning:

SUID is enabled

Setting SUID

Using chmod:

chmod u+s filename

Example:

chmod u+s program

Removing SUID

chmod u-s filename

4. SGID (Set Group ID)

What is SGID?

The SGID permission allows a program to run with the group permissions of the file, instead of the user’s group.


SGID on Executable Files

If SGID is set on a program:

  • it runs with the group privileges of the file owner group.

SGID on Directories

SGID has another important behavior on directories.

When SGID is set on a directory:

  • new files created inside the directory inherit the directory’s group.

Normally files inherit the creator’s group, but SGID overrides this behavior.


Example in IT Environments

A shared project directory:

/srv/project

Multiple developers belong to the group:

devteam

Directory permissions:

drwxrwsr-x

With SGID:

  • all files created in this directory belong to devteam
  • this ensures consistent group ownership.

Viewing SGID

Example:

drwxrwsr-x 2 root devteam 4096 Mar 10 10:00 project

Notice:

rws

in the group permission section.


Setting SGID

chmod g+s directory

Example:

chmod g+s /srv/project

Removing SGID

chmod g-s directory

5. Sticky Bit

What is the Sticky Bit?

The sticky bit is used mainly on directories.

It restricts file deletion.

When the sticky bit is set:

Users can delete files only if they:

  • own the file
  • own the directory
  • are root.

Why Sticky Bit is Important

Without the sticky bit:

  • any user with write permission could delete other users’ files in the directory.

With sticky bit:

  • users cannot delete files owned by others.

Common Linux Example

The directory:

/tmp

Permissions:

drwxrwxrwt

The t indicates the sticky bit.

This directory is used for temporary files by all users.

Sticky bit prevents users from deleting other users’ files.


Viewing Sticky Bit

Example:

drwxrwxrwt 10 root root 4096 Mar 10 10:00 /tmp

The t appears in the others execute position.


Setting Sticky Bit

chmod +t directory

Example:

chmod +t /shared/tmp

Removing Sticky Bit

chmod -t directory

6. Special Permission Numeric Values

Linux permissions can also be represented numerically.

Special permissions use an extra digit.

Format:

Special | Owner | Group | Others

Example:

4755

Meaning:

DigitMeaning
4SUID
2SGID
1Sticky

Examples:

PermissionNumeric
SUID4000
SGID2000
Sticky1000

Examples:

chmod 4755 program
chmod 2775 directory
chmod 1777 /tmp

7. Summary Table

FeaturePurposeUsed On
Symbolic LinkPoints to another fileFiles & directories
SUIDRun program as file ownerExecutables
SGIDRun program as file group / inherit groupFiles & directories
Sticky BitRestrict file deletionDirectories

8. Key Exam Points (Linux Essentials)

Students should remember:

  • Symbolic links are created using ln -s
  • Symbolic links contain paths to target files
  • If target is deleted → broken link
  • SUID runs programs as the file owner
  • SGID allows group inheritance in directories
  • Sticky bit prevents users from deleting others’ files
  • /tmp commonly uses the sticky bit
  • Special permissions appear as s or t in ls -l output
  • Numeric permission values:
    • SUID = 4
    • SGID = 2
    • Sticky = 1
Buy Me a Coffee