Skip to main content
All CollectionsJelasticSSH
SSH Access to Container - Manage Your Server Remotely
SSH Access to Container - Manage Your Server Remotely
Updated over a week ago

In this article, we will illustrate some of the most common handy commands to manage your server via SSH terminal as the platform allows establishing SSH access to any container on your account.

There are two ways to connect your server inside Jelastic PaaS over SSH:

  • Web SSH - click on the same-named option next to the required environment layer or particular container to quickly access and start managing it online directly through your browser, via the automatically opened terminal tab.

    1-Connect-server-web-ssh.png

SSH Gate - Based on preliminary generated SSH keys pair (where the public key should be added to your Account Settings, and the corresponding private key, handled at your local machine), you can connect to your server via any preferred local SSH client.

2-Connect-server-ssh-gate.png
  • After fulfilling all the requirements, you can establish an SSH connection by means of the corresponding command line (circled above) from the same-named tab of your account settings.

In this article, we will leverage the inbuilt Web SSH tool (to keep it simple and for quick access). Anyhow, the commands described below can be used similarly when working via a remote local client.

Important!:

  • Within the majority of servers within Jelastic PaaS (including custom Docker containers), you are automatically granted full root permissions while connected via SSH. For the rest (most of them - legacy nodes), a sufficient level of control is ensured with a set of additional allowed commands.

  • You can find the full list of terminal commands along with the appropriate options description, at the dedicated websites. In this article, we will illustrate some of the most common commands, to give you insights on the basics of operating with containers via the SSH protocol.

Navigation via Remote Container File System

We believe it is worth mentioning that the information provided in this section is rather for newbies than for an average developer, so you can skip it and proceed to more complex operations.

After entering the required container via console, you will get to the server home directory by default (commonly dedicated to storing your custom data and configs). The cd command is used, with the following available arguments to navigate amongst the folders:

  • {directory_path} - either name of the nested folder (where several slash-separated nesting levels can be specified) or a full path to the required directory relatively to the container root

  • .. - to navigate one level up within the file tree

  • ~ - to instantly switch to your working (server home) directory from any location

  • / - to instantly switch to the container root directory

3-Tomcat-ssh-connection-cofigurations.png

Consequently, the violet string next to the container hostname will change, indicating your current location.

Important!: If you are new to a stack runtime that your instance runs, most likely you would like to explore its inner structure first (e.g. tree of files & directories, available configuration files, etc). The most convenient way is to use the inbuilt Jelastic File Manager GUI (available when you click on Config next to the required server at your developer?s panel as shown below):

4-Manage-ssh-access.png

You may see the appropriate file tree in a dedicated tab below.

1- To create a new file or folder, execute the commands below:

  • touch [path-to/]{file} - to create a new file

  • mkdir [path-to/]{dir} - to create a new folder

where

{file} and {dir} - the preferred file or folder name (if being created in the current directory)

[path-to/] - optional parameter for the case, this new item should be placed in a different location.

5-Ssh-connection-tomcat-server.png

2- Use the command below to get the list of comprised files and directories at the current location (to ensure that the file and folder above have been actually created):

ls

6-Check-created-tomcat-ssh.png

3- Among the rest of the most common commands intended for file management, we need to mention:

  • cat - to operate with text files. Depending on stated args allows to view, merge and duplicate file content

  • cp - to copy files and directories

  • locate - to find the required file or directory within a server by its name (or part of it)

  • mv - to move and/or rename files and directories

  • PWD - to output the full path to the current directory (relative to the container root)

  • rm - to remove specified file or directory

Next, we will illustrate the default shell possibilities to monitor and manage your node?s metrics like resource consumption, running inside processes, etc.

Commands to View Server System Information

1- Use the w command to get a short summary of the current container state and ensure that, for example, no malefactor affects its performance and/or operability :

7-View-ssh-server-information.png

The output will provide you with some general system information in a header (namely - current system timestamp, instance uptime, number of logged users, and the average amount of active processes for the last 1/5/15 minutes) and details about the connected users below (their names, terminal type, source connection IP, login time, stats on the last activity and name of the currently active process(es), run on behalf).

Important!: The w command output does not include information on users, connected via a terminal emulator, due to the native shell implementation specifics.

2- All statistics on server RAM usage are stored within the /proc/meminfo file. Use the mentioned above cat command, to review the content:

cat /proc/meminfo

8-View-tomcat-server-ram-usage.png

Here, you can also check several data such as total memory allocated (MemTotal), unused memory (MemFree), memory used as a cache (Cached), and more.

3- Execute the following command line to display the basic software and hardware container data :

uname -a

9-Linux-node-ssh.png

There you can see info on a server kernel (name, version, release date), node hostname, CPU type, OS, etc.

How to Manage Container Processes Remotely via Terminal

1- You can monitor all running processes inside a container with the top command while connected over SSH:

10-Web-ssh-tasks.png

The information shown is constantly updated in a real-time mode, displaying info on all user?s processes (including system ones).

Press Ctrl + C to terminate the command execution and return to the console input mode.

2- Type in ps and run this command to display only your user?s active processes:

11-Web-ssh-tomcat.png

3- Kill is another command that allows terminating any running process, designated by its {pid} as an argument (the required process identifier can be found in the previous command?s output):

kill {pid}

12-Terminate-running-tomcat-process.png

You will notice that the run process, shown on the screen within the 2nd step of this section, was stopped because it is not listed among the active ones for now.

Operating Application Archives via SSH Console

You can fetch the necessary files from the Internet (e.g., your application archive) directly through the console, to store and/or deploy them within your server.

1- The wget command allows downloading files by the specified {link}:

wget {link}

13-Operate-archives-ssh-console.png

2- Next, you can unzip the downloaded archive with the same-named command:

unzip {archive}

where {archive} is a path to your compressed package.

14-Unzip-tomcat-archive-ssh.png

Consequently, all extracted files will be placed in a same-named (after the archive) folder inside the current directory.

Setting Custom Server Variables via SSH

1- You can check the list of default environment variables for any container within the .bash_profile file. It is located in the container?s home directory. Firstly, ensure that you have got the proper container directory and execute the next command:

cat .bash_profile

15-Setting-custom-tomcat-variables-ssh.png

2- By default, the .bash_profile file is not editable, so if you need to additionally set your own variables, write them down to the .bashrc file within the same folder (just create it, if missing). To finalize this, use any preferable text editor (e.g., vi):

16-Set-custom-variables-via-ssh.png

3- Here, new variables should be defined in the following format:

export {VAR_NAME}={VAR_VALUE}

where:

  • {VAR_NAME} - the name of the variable you want to create

  • {VAR_VALUE} - the value for the appropriate variable

    17-Export-tomcat-variables-via-ssh.png

Important!: The changes will be automatically applied when starting all further user sessions as the .bashrc file is read during the bash initiation. If you need to apply the made changes immediately, run the bash command to restart the shell.

4- Execute the command as below if you want to check whether your custom variable was successfully applied:

echo ${VAR_NAME}

18-Check-custom-tomcat-variables-via-ssh.png

You can see the {VAR_VALUE} string similar to the value you have just assigned to the ${VAR_NAME} variable in the .bashrc file.

Specifics of Certified Jelastic Containers Remote Management

At Jelastic PaaS, there are 2 types of software stack templates, used as a base when creating each of the containers:

  • dockerized - unified template model based on native Docker standard support with the generality of container management principles and functionality for all server types (e.g. regardless of whether it computes node, database server, or caching instance, etc..).
    You get automatically full control over the instance with root privileges granted when connecting to such a server via SSH. Also, it can perform any required operations inside a container.

  • certified software templates - based on native stack implementation, adapted according to platform specifics.

You will be logged in as a default server user by entering the server via SSH. In addition, you can also execute some additional options under a regular user account to increase the effectiveness of container management:

    • sudo sbin/service {service_name} {start|stop|restart|condrestart|status|reload|upgrade|help} - a set of commands to operate the main server process, defined with the {service_name} placeholder (where, depending on a server used, the possible values are: jetty, mysql, tomcat, memcached, mongod, postgresql, couchdb, glassfish-domain1, nginx, php-fpm and httpd)

    • sudo usr/bin/jem firewall {fwstart|fwstop} - to run/stop container firewall respectively

    • sudo usr/bin/jem nscd - to control the name-service caching daemon, which stores records for the most common name server requests (like passwd, hosts, group, etc)

    • sudo sbin/service rpcbind.service - to operate with the RPC bind service, used to map user-readable names to program numbers that handle incoming RPC calls

Despite being run in a sudo mode, any of the commands above do not require entering server admin root password. By so, you to take advantage of all the required container functionality even with regular account permissions.

As you know all the required basics to manage your containers via console, you can leverage even more PaaS flexibility while running your applications.

Did this answer your question?