In this article, we will help you get the basics of what is a terminal, how it is related to SSH, how to connect with SSH and basic usage of the most popular Linux and SSH commands that can be used with terminal both from Linux or Windows machines.
What is a Terminal and how is SSH related to it?
A terminal is that green black screen in which you would usually see a hacker sitting in front in the movies. Outside of what the big screen industry commonly promotes, it’s used on a day to day basis to interact with your computer or server by executing commands directly, without the use of a Graphic Interface. The benefits for an experienced user is the speed and the performance you get on top of the fact that graphics interfaces normally stuck when executing complex commands.
SSH stands for Secure Shell which is a way for you to safely connect to an external computer, not necessarily in your home or continent and execute commands on it as if you’re actually executing them on your own machine. This allows you to administrate remove computers (servers) without the use of actually being at their location physically.
Most users are familiar with their graphic interface from their Windows or Mac and are comfortable with clicking around different windows to perform operations. For example, you can easily open your browser and check your favorite website or launch a desktop application for the time and set a reminder for tomorrow.
Those actions, performed by clicking around your applications, are interacting with the programs (or widely referred to as applications nowadays) on your computer and giving them instructions on what to do. Some of those programs or applications also provide means with which you can actually perform the exact same thing as you would through its graphical interface but actually do it from your computer’s console, thus being called Command Line Interface or CLI for short.
The various ways that you can interact with your computer’s folders and files are also available to be done through the terminal. So,
What is the difference between a graphics interface and a terminal and what does SSH has to do with any of it?
The graphics interface is an easy way for you to instruct your machine to perform a specific action. Most of those actions can also be performed through the terminal. If you’re administrating a remote server and there is no graphical interface to work with (as is the case with Linux servers) you are required to work with a terminal.
The way that you connect to the external server’s terminal is through software called SSH.
Connecting with SSH
You can connect with SSH with a User and its Password. Those are the Users present on the external server. Some safer configurations require that you have a key with which you can connect directly. The way keys work is that you need to generate one on the external machine and then download it on your local computer. Then you can use the downloaded key to connect to your User on the external server.
This is done with using the SSH keygen command
First, we’ll start generating the key
user@server$: ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org"
You will have the key’s information created, then you’re required to save that information into a file. You will be prompted to just press Enter to have it saved in your default .ssh directory as id_rsa
After that you will be prompted to enter a passphrase for the key, this is the password for your key.
When you have generated the key on the external machine and have downloaded it to yours you can start connecting over SSH to the external server.
The Linux Command Line
After using SSH to connect to an external Linux machine you will have access to your User’s Command Line. The Linux Operating System is built with security being one of its main priorities and as such the folders (called directories) and files have permissions on them for access. Depending on those permissions the User with which you connect will have access to different commands and be able to interact with the server in a different way. For example, a normal User will not have access to the tools available to an administrator.
One of the most common issues when executing commands through SSH is that you might actually have the command missing. For example, when working with PHP you might use Composer, it is a Command Line Interface Tool which will allow you to perform various operations for your PHP installations (like Laravel). One of the issues that might occur during the execution of the Composer’s functionality is to find out that the Composer is missing but to actually have it present in your account as an executable file.
Fixing the Command not Found error
When you log in with SSH to an external server you actually start a new Shell Session. In that session, your terminal is required to understand a certain set of variables which help and dictate the terminal’s workflow. Those variables are called Shell Variables and one common way to find out some of them is to run the env command
The variables are loaded with each new session that you start. One of the variables is called $PATH and this one instructs your terminal in which directories (remember – the Linux word for folders) it should look for executable commands. If at any of those directories the command is not present – you will end up receiving the Command not Found error.
For this, you can easily add the directory in which your executable is present to the path variable, once this is done you will be able to directly call the executable as it’s already present in the $PATH of which your shell is looking for commands.
Linux SSH Commands
There is a variety of Linux commands that can be run through SSH. Most of those commands are written by developers and represent actual programs which you might also see to have Graphical User Interfaces, like your browser.
Each Linux Operating System also comes with many of its own pre-installed commands, some which present among all other Linux distributions, those involve commands for working with:
– The file system
– Text formatting
– Making requests over the internet
– Network administration
If you’re interested in knowing more about the Linux commands you can take a look at our Knowledge Base. You can find the most common and widely used SSH commands for beginners and experts. Also, you can get a new shared Linux hosting account or a Linux Dedicated server on a greatly discounted price and test your knowledge and administer your hosting account using Linux commands under SSH