Difficulty: Advanced
By default many application servers (with the exception of VPS and Docker containers) use an application-specific user with restricted access to prevent issues. There are occasional times where you might be using an application server and need root access to install a server-level package. To give that user sudo access you can use the following guide.
Note: Running commands on a container as the root user has the potential of breaking your application. Please proceed with caution
Click Import from the top menu bar
Go to the JPS Import tab
Paste the following code and click Import
type: update
name: Root Access
targetNodes:
nodeGroup: '*'
onInstall:
- cmd[${targetNodes.nodeGroup}]: |-
TARGET_UID=$(id -u jelastic 2>/dev/null) || TARGET_UID="700"
getent passwd "${TARGET_UID}" &>/dev/null && TARGET_USER=$(getent passwd "${TARGET_UID}" | cut -d: -f1) || TARGET_USER="jelastic"
sed -i "\$a${TARGET_USER}\ ALL=NOPASSWD\:\ ALL" /etc/sudoers; echo ${TARGET_USER}
user: root
- setGlobals:
sudo_user: ${response.out}
onUninstall:
cmd[${targetNodes.nodeGroup}]: |-
sed -i "/${globals.sudo_user}\ ALL=NOPASSWD\:\ ALL/d" /etc/sudoers
user: root
Select the appropriate environment and container and click Install
Once install is complete, you can execute the command sudo su
to become root within the SSH shell of the container.