{"id":209,"date":"2021-07-23T12:19:23","date_gmt":"2021-07-23T12:19:23","guid":{"rendered":"https:\/\/ssdsunucum.com\/blog\/virtfs-jailed-shell\/"},"modified":"2021-07-23T12:19:23","modified_gmt":"2021-07-23T12:19:23","slug":"virtfs-jailed-shell","status":"publish","type":"post","link":"https:\/\/ssdsunucum.com\/blog\/virtfs-jailed-shell\/","title":{"rendered":"VirtFS Jailed Shell"},"content":{"rendered":"<\/p>\n<div class=\"col-md-9\">\n<div class=\"flex-column flex-md-row article-header\"><\/div>\n<hr>\n<h2 id=\"overview\">Overview<\/h2>\n<p>cPanel &#038; WHM uses VirtFS to provide a jailed shell environment for users who connect to a server via SSH. The jailed shell acts as a container for the user, and does not allow the user to access other users\u2019 home directories on the server.<\/p>\n<ul>\n<li>\n<p>Unlike a normal shell environment, a jailed shell environment increases security for a server\u2019s other users.<\/p>\n<\/li>\n<li>\n<p>Users in a jailed shell environment can run otherwise-unavailable commands (for example, <code>crontab<\/code> and <code>passwd<\/code>).<\/p>\n<\/li>\n<\/ul>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>\n<p>CentOS 6 and older support a maximum of <strong>only<\/strong> 256 jailshell users on systems that use the Apache <code>mod_ruid2<\/code> module.<\/p>\n<\/li>\n<li>\n<p>Some customers have reported performance and connection issues when they attempt to mount more than 4000 targets in a Virtuozzo environment.<\/p>\n<\/li>\n<li>\n<p>If you enable a jailed shell on a server runs CloudLinux\u2122, you may cause a security vulnerability with symlinks to files outside of the caged directory. To solve this issue, you <strong>must<\/strong> enable link traversal protection. For more information, read CloudLinux\u2019s Link traversal protection documentation.<\/p>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<h2 id=\"the-virtfs-directory\">The virtfs directory<\/h2>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n<p>Do <strong>not<\/strong> use the <code>rm<\/code> command to remove any mounted file or directory within the <code>\/home\/virtfs\/<\/code> directory. If you run this on any mounted file or directory within the <code>\/home\/virtfs\/<\/code> directory, you will also delete all of the files in the directory to which it is mounted. This action <strong>will<\/strong> render your server <strong>nonfunctional<\/strong>.<\/p>\n<\/p><\/div>\n<\/div>\n<p>When a user logs in to a jailed shell environment via SSH or SFTP for the first time, the system creates the <code>\/home\/virtfs\/<\/code> directory. This directory contains configuration files, utilities, and BIND mounts.<\/p>\n<ul>\n<li>\n<p>You <strong>cannot<\/strong> prevent the creation of this directory or disable it.<\/p>\n<\/li>\n<li>\n<p>This directory does <strong>not<\/strong> use any disk space. However, because it is a virtual mount point, some commands (for example, <code>du<\/code>) report that the directory uses disk space.<\/p>\n<\/li>\n<li>\n<p>BIND mounts create a virtual link between two locations on the file system. For example, if a user views the contents of the <code>\/home\/virtfs\/username\/usr\/bin\/<\/code> directory, the user actually sees the contents of the <code>\/usr\/bin\/<\/code> directory. For more information about BIND mounts, run the <code>man 8 mount<\/code> command.<\/p>\n<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>\n<p>Servers that run CentOS 7 or 8, CloudLinux\u2122 7 or 8, AlmaLinux 8, or Red Hat\u00ae Enterprise Linux\u00ae (RHEL) 7 may use additional mount points for common system paths (for example, <code>\/usr\/bin<\/code>). Do <strong>not<\/strong> dismount these mount points.<\/p>\n<\/li>\n<li>\n<p>On servers that run CentOS 7 or 8, CloudLinux 7 or 8, AlmaLinux 8, or RHEL 7, the <code>\/etc\/mtab<\/code> symlink points to the <code>\/proc\/self\/mounts<\/code> file.<\/p>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<h2 id=\"enable-a-jailed-shell-environment\">Enable a jailed shell environment<\/h2>\n<p>WHM includes two options to activate a jailed shell environment. The option that you use depends on the type of users for whom you wish to enable jailed shells.<\/p>\n<p>To enable a jailed shell environment for all new and modified users, use the <em>Use cPanel\u00ae jailshell by default<\/em> option in WHM\u2019s <em>Tweak Settings<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Server Configuration<\/em> &gt;&gt; <em>Tweak Settings<\/em>).<\/p>\n<ul>\n<li>\n<p>This option allows you to force the use of a jailed shell for new accounts and accounts that you subsequently edit in the following interfaces:<\/p>\n<ul>\n<li>\n<p>WHM\u2019s <em>Modify an Account<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Account Functions<\/em> &gt;&gt; <em>Modify An Account<\/em>).<\/p>\n<\/li>\n<li>\n<p>WHM\u2019s <em>Upgrade\/Downgrade an Account<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Account Functions<\/em> &gt;&gt; <em>Upgrade\/Downgrade An Account<\/em>).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>This option does <strong>not<\/strong> affect accounts that already exist on the server but that you have not edited in these interfaces.<\/p>\n<\/li>\n<\/ul>\n<p>To enable a jailed shell environment for a specific user, use WHM\u2019s <em>Manage Shell Access<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Account Functions<\/em> &gt;&gt; <em>Manage Shell Access<\/em>).<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>When you enable jailed shell access for a user, the system sets the user\u2019s shell to the <code>\/usr\/local\/cpanel\/bin\/jailshell<\/code> location.<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"exim-and-virtfs\">Exim and VirtFS<\/h3>\n<p>When a user\u2019s shell location is <code>\/usr\/local\/cpanel\/bin\/jailshell<\/code> (jailed shell is enabled) or <code>\/usr\/local\/cpanel\/bin\/noshell<\/code> (all shells are disabled), Exim runs any process from alias or filter files inside VirtFS. This action provides extra security because Exim commands run in a jailed shell and do not affect other users.<\/p>\n<h3 id=\"csf-or-lfd-alerts\">CSF or LFD alerts<\/h3>\n<p>If you use a utility that monitors system changes (for example, CFS or LFD), you may see an alert that resembles the following example after you upgrade:<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-text\" data-lang=\"text\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-text\" data-lang=\"text\">The following list of files have FAILED the md5sum comparison test. This means that the file has been changed in some way.\nThis could be a result of an OS update or application upgrade. If the change is unexpected it should be investigated:\n\n\/bin\/crontab: FAILED\n\/bin\/passwd: FAILED<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<p>This is a false positive warning. cPanel &#038; WHM uses the <code>\/bin\/crontab<\/code> and <code>\/bin\/passwd<\/code> symlinks to link to files in the <code>\/usr\/bin<\/code> directory. These symlinks allow jailed shell environments to access the <code>crontab<\/code> and <code>passwd<\/code> commands.<\/p>\n<h2 id=\"disable-or-remove-a-jailed-shell-environment\">Disable or remove a jailed shell environment<\/h2>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n<p>You <strong>cannot<\/strong> completely remove the jailed shell system (VirtFS). The directions below remove a jailed shell environment, but <strong>cannot<\/strong> prevent the recreation of the jailed shell environment. The following processes may recreate the jailed shell environment:<\/p>\n<ul>\n<li>\n<p>Exim processing filters.<\/p>\n<\/li>\n<li>\n<p>Piped email addresses.<\/p>\n<\/li>\n<li>\n<p>Cron jobs.<\/p>\n<\/li>\n<li>\n<p>Jailed Apache virtual hosts that use the <code>mod_ruid2<\/code> module via the <em>EXPERIMENTAL: Jail Apache Virtual Hosts using mod_ruid2 and cPanel\u00ae jailshell<\/em> option in WHM\u2019s <em>Tweak Settings<\/em> interface (<em>WHM &gt;&gt; Home &gt;&gt; Server Configuration &gt;&gt; Tweak Settings<\/em>).<\/p>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"disable-the-jailed-shell-environment\">Disable the jailed shell environment<\/h3>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n        You <strong>cannot<\/strong> disable the <code>\/home\/virtfs\/<\/code> directory for your users, even if you disable jailed shell access. For more information about the <code>\/home\/virtfs\/<\/code> directory, read the The <code>\/home\/virtfs\/<\/code> directory section above.\n    <\/div>\n<\/div>\n<p>To disable the jailed shell environment for a specific user, use WHM\u2019s <em>Manage Shell Access<\/em> interface (<em>Home<\/em> &gt;&gt; <em>Account Functions<\/em> &gt;&gt; <em>Manage Shell Access<\/em>).<\/p>\n<p>To disable the jailed shell environment for all of the users on your server, perform the following steps:<\/p>\n<ol>\n<li>\n<p>Disable the <em>Use cPanel\u00ae jailshell by default<\/em> option in WHM\u2019s <em>Tweak Settings<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Server Configuration<\/em> &gt;&gt; <em>Tweak Settings<\/em>).<\/p>\n<\/li>\n<li>\n<p>Select <em>Disabled Shell<\/em> for all of the server\u2019s accounts in WHM\u2019s <em>Manage Shell Access<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Account Functions<\/em> &gt;&gt; <em>Manage Shell Access<\/em>).<\/p>\n<\/li>\n<\/ol>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>When you disable jailed shell access, the system sets the users\u2019 shells to the <code>\/usr\/local\/cpanel\/bin\/noshell<\/code> location. With this location, the user retains access to SFTP in a non-jailed environment.<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"remove-a-user-s-jailed-shell-environment\">Remove a user\u2019s jailed shell environment<\/h3>\n<p>To remove a jailed shell environment, perform the following steps:<\/p>\n<ol>\n<li>\n<p>Disable the jailed shell environment for the user in WHM\u2019s <em>Manage Shell Access<\/em> interface (<em>WHM<\/em> &gt;&gt; <em>Home<\/em> &gt;&gt; <em>Account Functions<\/em> &gt;&gt; <em>Manage Shell Access<\/em>).<\/p>\n<\/li>\n<li>\n<p>To unmount the VirtFS BIND mounts, run the following command, where <code>username<\/code> is the desired account username:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-text\" data-lang=\"text\">umount \/home\/virtfs\/username\/usr\/bin<\/code><\/pre>\n<\/div>\n<\/li>\n<\/ol>\n<h3 id=\"the-clear-orphaned-virtfs-mounts-script\">The clear orphaned VirtFS mounts script<\/h3>\n<p>You can run the <code>\/usr\/local\/cpanel\/scripts\/clear_orphaned_virtfs_mounts<\/code> script to unmount the BIND mounts for users who no longer exist or who no longer use a jailed shell environment. This script removes the <code>\/home\/virtfs\/username\/<\/code> directory and its contents.<\/p>\n<p>To force the removal of all VirtFS mount points, run the following command, where <code>username<\/code> is an account\u2019s username:<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-text\" data-lang=\"text\">\/usr\/local\/cpanel\/scripts\/clear_orphaned_virtfs_mounts --clearall<\/code><\/pre>\n<\/div>\n<p>To check your system for VirtFS mount points, run the following command, where <code>username<\/code> is the desired account username:<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-text\" data-lang=\"text\">grep -i username \/proc\/mounts<\/code><\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview cPanel &#038; WHM uses VirtFS to provide a jailed shell environment for users who connect to a server via SSH. The jailed shell acts as a container for the user, and does not allow the user to access other users\u2019 home directories on the server. Unlike a normal shell environment, a jailed shell environment &hellip;<\/p>\n","protected":false},"author":1,"featured_media":210,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/209"}],"collection":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":0,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media\/210"}],"wp:attachment":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}