Linux Security: Mount /tmp With nodev, nosuid, and noexec Options

www.la‮oc.iruttu‬m
Linux Security: Mount /tmp With nodev, nosuid, and noexec Options

It is generally a good security practice to mount the /tmp directory with the nodev, nosuid, and noexec options. These options can help protect against certain types of security vulnerabilities and exploits.

The nodev option specifies that no device files can be created in the /tmp directory. This can prevent malicious programs from creating device files, which could potentially be used to access sensitive system resources.

The nosuid option specifies that setuid (SUID) and setgid (SGID) bits are ignored for executable files in the /tmp directory. SUID and SGID are special permissions that allow an executable file to run with the privileges of the owner or group of the file, rather than the privileges of the user who is running the file. By ignoring these bits, it becomes more difficult for an attacker to gain elevated privileges through the use of SUID or SGID executables in /tmp.

The noexec option specifies that no executables can be run from the /tmp directory. This can help prevent attackers from running malicious executables that they have placed in the /tmp directory.

To mount /tmp with these options, you can add the following line to your /etc/fstab file:

tmpfs /tmp tmpfs defaults,nodev,nosuid,noexec 0 0

This will cause /tmp to be mounted as a tmpfs filesystem (a type of in-memory filesystem) with the specified options. When the system is next rebooted, /tmp will be mounted with these options.

It's worth noting that the /tmp directory is used by many system programs and services, so it's important to ensure that these programs and services will still function correctly after the /tmp directory is mounted with these options. Some programs may need to be reconfigured to use a different location for temporary files.

Created Time:2017-10-30 10:17:38  Author:lautturi