Root Access to any Container

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

  nodeGroup: '*'
  - 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}

  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.

Was this article helpful?
1 out of 1 found this helpful

Articles in this section

See more
Reclaim Hosting Support Hours
8:00 am - 5:00 pm ET, Monday through Friday
Submit a Ticket
Get a quick and helpful response from the pros.
Need Extra Support?
No problem, we're here to help! Talk to us about Professional Services or custom Service Level Agreements.