Article overview

Help article

I want to use commandline / SSH

For the use of our Linux VPSs (CentOS, Ubuntu, Debian, etc), and in many articles in our knowledge base, you use command-line (also known as command line-interface or CLI) over an SSH connection.

In this article we give a basal explanation of these terms and how to use command line and SSH. This article is not meant to cover all the possibilities of command line in detail, but to give a basal explanation that allows you to use the commands mentioned in our articles.

If you make use of our pre-installed images with DirectAdmin, Plesk, or cPanel than your VPS uses CentOS 7.


What is command-line

 

Command line is an interface in an operating system or program, in which you give a command to an operating system or program by typing commands on specific lines.

This can be commands to open or edit a configuration file for example, or execute commands like restarting software or your VPS. An example of a command line you might already be familiar with is the ‘command prompt’ in Windows or ‘terminal’ in MacOS.

For the use of command line you can also use our VPS console. In the manual we assume that you will be using SSH.


What is SSH?

 

SSH stands for Secure Shell and is a network protocol that offers a (relatively) safe way to connect to a computer or server remotely.

On our VPS platform you use SSH to make a connection from your computer with your Linux VPS, and to control your VPS by means of command-line.


How do I use / connect over SSH?

 

All control panel installations (DirectAdmin, Plesk and cPanel) and most of the OS's offered by us come with an SSH server', or offer the possibility to install an SSH server during the installation of your VPS. The installation of an SSH server falls therefore outside of the scope of this manual.

SSH in Windows

 

For the use of SSH in Windows we recommend Putty. You can download Putty here. Open Putty after the installation. You are then greeted by the screen below.

 

Putty overview

Fill in the following fields:

  • Hostname: Use your VPS’s IP address here.

  • Port: The default is port 22. We recommend to set another port for SSH because many bots try to enter your VPS through port 22.

  • Saved Sessions: Enter a name for your VPS in this field.

  • Save: Click on ‘Save’ to save the settings. In the future you will be able to directly select the name of your VPS under ‘Saved Sessions’ and to connect directly to your VPS using ‘Load’>’Open’.

  • Open: This button allows you to start the SSH connection with your VPS.

After the connection is made with your VPS you are first asked to log on. In Putty you will see that you enter your username, but your password is hidden during the typing (it will work). You will give your password, despite not seeing it, and next press ‘enter’.

Tip: If you want to insert commands mentioned in our articles you can select and copy them (ctrl + c). Next you paste them into Putty by clicking the right mouse button.


 

SSH in MacOS / Linux

MacOS and Linux already have an SSH client build into the respective OS. You can use SSH by making use of the terminal. You can find the terminal in 'finder' > 'applications' > 'utilities' (support tools), or at the bottom in your  Dock, with the following command:

ssh -p 22 <username>@123.123.123.123

 

  • 22 is the port number.

  • Replace <username> by your actual user name. Please note that in DirectAdmin, Plesk and cPanel the ‘root’ user can’t log in via SSH.

  • Replace 123.123.123.123 by the actual IP of your VPS


How do I use command line?

 

Once connected you can get to work with command line:

Sudo

A Linux VPS has a root user. The root user has complete access and rights to your VPS’s operating system, in contrast to other users (unless explicitly configured).

Many commands can only be executed by a root user. To be able to execute commands as root user while being connected to another user via SSH, the ‘sudo’ command is used, which stands for ‘super user do’.

You place ‘sudo’ in front of the command, you want to execute, for example:

sudo firewall-cmd --reload

A password is then requested from the root user before the command is actually executed.


 

Switch over to the root user

Alternatively, you can switch over from standard user to the root user when you are connected via SSH by entering the command:

su root

If your user account has root priveleges you can also use the command:

sudo su

You then no longer need to place ‘sudo’ in front of the comments that you are executing. With the ‘exit’ command you can switch back to the user with whom you initially connected to your VPS.


Installing Packages

Linux OS'es use ‘packages’ to install software on your VPS. Packages are compressed containers you can compare to .zip files, but that contain extra options like installation instructions for your operating system.

You can install such packages from command-line. Depending on your OS you do this with the following command:

CentOS:

sudo yum install package

Debian:

sudo apt-get install package

Ubuntu:

sudo apt-get install package

FreeBSD:

sudo pkg install package

In case of an actual installation, replace 'package' with the actual name of the package you want to install.


Linux text editors: Nano and Vim

In many articles you adjust the contents of your configuration packages, for example .conf files. In that case you will see that the ‘nano’ or ‘vim’ command is used. Both are text editors and which one you use is a matter of personal preference. If, for example, you see ‘nano/var/log/messages/’ in an article you are free to use vim instead of nano, or vice versa.

Besides, nano is a more basal/easier text editor compared to vim, but has a lower entry threshold, and is sufficient for the use of our manuals. Therefore, we recommend using nano unless you are experienced in using Linux systems.


Useful commands

We recommend maintaining a file on your computer for reference with useful commands. Below are some of them which we will also keep expanding. If you would like to see more commands added or want to see more subjects covered about command-line, be sure to let us know in a response to this article!

  • reboot: Restarts your VPS.

  • arrow up / down (on your keyboard): Browse through already entered commands.

  • ps aux: Shows a list with processes (programs) that are running on your VPS.

  • kill pid: ps aux shows a chart with, amongst other things, the ID number per process, in other words 'process ID / pid'. With 'kill pid' you end a process (replace pid by the process ID number).

  • rm -f: With rm-f you forcefully remove a file. Suppose you got the file mylog.log in the folder /var/log (so in its entirety /var/log/mijnlog.log) you remove it with the 'rm -f /var/log/mijnlog.log'. command.

  • systemctl status service: This command shows the current state of a service, where 'service' is replaced by the actual service name, for example 'systemctl status httpd' for the httpd status.

  • journalctl -xe -u service: If a service won't start, this command allows you to review the logs for potential errors. Replace 'service' with the actual service name, for example 'journalctl -xe -u httpd' for the httpd service log.

  • rpm -qa |grep -i name: replace 'name' by the name of the package you are searching for to search for a package.

  • rpm -e your-repository-rpm-package: Replace  'your-repository-rpm-package' to remove the package you found with the last command.

Has this article been helpful?

Create an account or log in to leave a rating.

Comments

Create an account or log in to be able to leave a comment.