{"id":5464,"date":"2015-12-21T11:58:15","date_gmt":"2015-12-21T03:58:15","guid":{"rendered":"http:\/\/rmohan.com\/?p=5464"},"modified":"2015-12-21T11:58:15","modified_gmt":"2015-12-21T03:58:15","slug":"increasing-linux-server-security-with-nodev-nosuid-and-no-exec-options","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5464","title":{"rendered":"Increasing Linux server security with nodev, nosuid and no exec options"},"content":{"rendered":"<div><strong>Expertise level:<\/strong>\u00a0Advanced<\/div>\n<div>\n<div>Hackers can use temporary storage directories such as\u00a0<em>\/tmp<\/em>\u00a0to store and execute unwanted programs and hack into a server. Other temporary storage directories that can be used for malicious activities are<em>\u00a0\/var\/tmp<\/em>\u00a0and\u00a0<em>\/dev\/shm.\u00a0<\/em>Follow these steps to secure your Linux server against this vulnerability:<\/div>\n<div><\/div>\n<div><strong>Add nodev, nosuid, and noexec options to \/tmp:<\/strong><\/div>\n<div>\n<p>1. Edit the file\u00a0<kbd>\/etc\/fstab<\/kbd>, enter:<br \/>\n<code>vi \/etc\/fstab<\/code><br \/>\n2. Locate the \/tmp line:<\/p>\n<pre>UUID=0aef28b9-3d11-4ab4-a0d4-d53d7b4d3aa4 \/tmp                    ext4    defaults        1 2<\/pre>\n<p>3. Append the text\u00a0<kbd>,nodev,nosuid,noexec<\/kbd>\u00a0to the list of mount options in column<\/p>\n<p>4. The entry should look like \u00a0this:<\/p>\n<pre>UUID=0aef28b9-3d11-4ab4-a0d4-d53d7b4d3aa4 \/tmp                    ext4    defaults,nodev,nosuid,noexec        1 2<\/pre>\n<p>5. Save and close the file.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Add nodev, nosuid, and noexec options to \/dev\/shm<\/strong><\/p>\n<p>1. Edit the file\u00a0<kbd>\/etc\/fstab<\/kbd>, enter:<br \/>\n<code>vi \/etc\/fstab<\/code><br \/>\n2. Locate the \/dev\/shm line:<\/p>\n<pre>tmpfs                   \/dev\/shm                tmpfs   defaults        0 0<\/pre>\n<p>3. Append the text\u00a0<kbd>,nodev,nosuid,noexec<\/kbd>\u00a0to the list of mount options in column<\/p>\n<p>4. The entry should look like this:<\/p>\n<pre>tmpfs                   \/dev\/shm                tmpfs   defaults,nodev,nosuid,noexec        0 0<\/pre>\n<p>5. Save and close the file.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>About \/var\/tmp<\/strong><\/p>\n<p>Make sure you bind \/var\/tmp to \/tmp:<\/p>\n<p>1. Edit the file\u00a0<kbd>\/etc\/fstab<\/kbd>, enter:<br \/>\n<code>vi \/etc\/fstab<\/code><br \/>\n2. Append the following line:<\/p>\n<pre>\/tmp \/var\/tmp none rw,noexec,nosuid,nodev,bind 0 0<\/pre>\n<p>3. Save and close the file.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Set nodev, nosuid, and noexec options without rebooting the Linux server<\/strong><\/p>\n<p>1. Type the following command as root user:<\/p>\n<pre> # Bind \/var\/tmp to \/tmp\r\n mount -o rw,noexec,nosuid,nodev,bind \/tmp\/ \/var\/tmp\/\r\n # Remount \/tmp\r\n mount -o remount,noexec,nosuid,nodev \/tmp\r\n # Remount \/dev\/shm\r\n mount -o remount,noexec,nosuid,nodev \/dev\/shm\r\n<\/pre>\n<p>2. Verify new settings:<\/p>\n<p><code><br \/>\nmount | egrep --color -w '^(tmpfs|\/tmp)|\/tmp'<\/code><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Expertise level: Advanced Hackers can use temporary storage directories such as \/tmp to store and execute unwanted programs and hack into a server. Other temporary storage directories that can be used for malicious activities are \/var\/tmp and \/dev\/shm. Follow these steps to secure your Linux server against this vulnerability: Add nodev, nosuid, and noexec options [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73,4,17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5464"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5464"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5464\/revisions"}],"predecessor-version":[{"id":5465,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5464\/revisions\/5465"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}