There is an option in whm/cpanel to enable jailshell access for any hosting account.
I want to know if it is possible to enable that option for any or all cpanel hosting accounts through command line.
Jailshell can be enabled for a user in WHM by navigating to Manage Shell Access under Account Functions.
To setup jailshell access for a user from the command line interface, simply use the operating system's change shell command as root, for example:
# username=CPANELUSERNAME;
# chsh -s /usr/local/cpanel/bin/jailshell ${username}
You may also be interested in these sections of cPanel's documentation:
Remember:
${username}
and $username
both refer to a local variable called username
.
Suppose your username is fahad
.
If you want to change the shell without using the variable, it would look like this:
# chsh -s /usr/local/cpanel/bin/jailshell fahad
If you typed chsh -s /usr/local/cpanel/bin/jailshell ${username}
without setting the variable username
first, it would be equivalent to ch -s /usr/local/cpanel/bin/jailshell
without any parameter after to designate the user whose shell you want to change, and then the command defaults to changing the shell for the currently logged in user.
You also said that you're getting this error:
'0' is not a valid user id, and may not run jailshell (cpanel users file missing).
That is caused because the root account has been set to use jailshell, though it should not be. This could have happened when you executed the above command without passing the parameter for the user account (i.e. by using an unset variable).
You may wish to reset your shell to /bin/bash
in WHM by navigating to Manage Shell Access under Account Functions. Alternatively, if you are comfortable doing so, you can edit the change is in the /etc/password
file manually by running vipw
(as the file cannot be edited directly easily under most systems).