Linux Commands

Essential SSH Commands You Should Know

As a network protocol, SSH is essential for accessing remote machines securely and executing commands. It comes with fantastic security components when accessing other computing devices remotely. Notably, its ability to encrypt data and information sent over insecure networks is arguably its greatest strength.

SSH features an array of commands to enable its functionality. And just like any other network protocol, understanding these commands is the first step towards understanding how to enable and use SSH.

We will handle the essential SSH commands that every network administrator should know. They include the following:

LS Command

The SHH ls command comes in handy in providing a list of the directories or files in your network. The ls command comes with the following flags:

  • ls – This flag lists the contents of a file or a directory.
  • ls -1 – Displays the file/directory contents with one entry in each line.
  • ls –l – Displays every detail of the file/directory.
  • ls –lh – Lists the file/directory content in full, human-readable sizes and formats.
  • ls –lt – Provides the contents of a directory in order of the last modified time.
  • l –a – Provides a display of hidden directories and files.
  • ls –ld – Provides the directory information.

A simple ls command provides the following display. We will use the linhint.com as our hostname:

PWD Command

This utility displays a clear path of your system’s current working directory. It is useable when using SSH to access your site hosting on shared servers. As you probably already know, shared servers do not outline your directory path. Using this command could deliver a result such as the following:

CD Command (Change Directory Command)

This is the command to use if you want to jump between files or directories. It is arguably one of the most straightforward SSH commands to execute. All you need to do is to type cd and add the directory you want to move to.

For instance, if you want to access the home directory of your server, you will need to enter the following command:

Using this command is even more interesting as it allows you to provide a clearer path to directories in your server. For example:

The previous command takes you to “AnotherDirectory.”

MKDIR Command (Make Directory Command)

SSH allows you to create directories or files into your server, remotely. You can achieve this using the mkdir command which features the following syntax:

For example, if you intend to create a new folder and name it technical, you can type the following command:

RM Command

This command comes in handy in removing or deleting files or directories. You can also use it to delete an entire directory. Its syntax is as shown in the following illustration:

For example, you can remove or delete the enablingSSH file from your servers using the following command:

You can also delete an entire folder using the –r flag as shown in the following illustration. Doing this also gets rid of all the subfolders within the folder.

CP Command

The cp command is related to the rm utility. It comes in handy in copying folders and files. The syntax for this SSH tool is:

In the syntax, the source is the file you want to copy, while the destination is its duplicate. For example, you can duplicate “myfile.txt” file using the following command:

You can also copy the file into a different folder. For example:

MV Command

Unlike the cp tool that copies or duplicates your file, the mv utility moves the file to a new folder or directory. It features the following syntax:

You can use the previous command to move the files from one folder to another. For example, we want to move the “myfile.txt” file from /home/linhint/ftp to /home/linhint/myfolder. The command looks like what is in the following illustration:

In the cp utility, the –R option is vital when you want to copy all the files or folders within the directory. However, you do not need to use the –R flag when moving folders with the mv SSH tool. For example, the following command will conveniently move all the subfolders and files from ftp to myfolder:

Cat Command

If you want to inspect the contents of a file, the cat command comes in handy. It displays the content of a file and features the following tool:

You can also use the same tool to create new files by merging two files. For instance, the following utility merges the “info.txt” and “info2.txt” and saves it as “merged.info”.

History Command

Finally, we have the history command. This SSH tool displays your list of the last used commands. You need to follow it with a specified number. For example, typing 15 after the utility shows the previous 15 utilities used.

Conclusion

The given examples are some of the basic Linux SSH commands. Understanding them is vital to administrating your VPS or Linux server. This article has up to 10 utilities that you will find very common in your day-to-day server management.

Sources

About the author

Kennedy Brian

Brian is a computer scientist with a bias for software development, programming, and technical content development. He has been in the profession since 2015. He reads novels, jogs, or plays table tennis whenever not on gadgets. He is an expert in Python, SQL, Java, and data and network security.