Blog

Basic Commands of SSH in 2021

Secure Shell is a secure and encrypted connection protocol providing remote and secure sign-ins over unsecured connections. The connection runs in the client-server model, so the connection is secured by the SSH client connecting to the SSH server.

SSH protocol is used to connect securely to the remote server. If you want to establish ssh connection then you go for the ssh client is Putty Key. It helps to create ssh public and private keys. It will ask you to enter the server’s IP and the port number into the corresponding fields.

How to Access Remote Server?

Remote access, also known as remote login, is the ability to access the data collected on a computer from a remote location. It permits you to open, edit, and save records located on your device from anywhere in the world.

There are several ways to set up remote access -

  • With LAN (local area network)

  • WAN (wide area network)

  • VPN (a virtual private network)

Access is possible as long as there is a connection between devices.

How to Setup SSH Client for Accessing Remote Server

For obtaining the remote server, there are two popular methods. If you already have ssh connection then you may use ssh client for easy and better use. You have to install putty from puttykey.com.

The second option is - Using the built-in command prompt (Windows) or terminal shell (Linux, macOS). You will need to write - ssh user@serverip

Note - Remember to replace “user” with your unique username and “serverip” with your server’s applied or shared IP address.

Once you click the install button in putty you redirect to the command prompt on the terminal, and you are prompted to the passwords.

10 Basic SSH Commands {Updated}

Try best basic ssh commands with their syntaxes and useful options.

  1. ls

This SSH command is used to list all files and directories. After accessing ls, you will see an output that looks like this - There are also a few useful options that you can combine with it -

  • l — represents the details of the files, such as size, modified date and time, the owner, and the support.

  • a — shows hidden files and directories.

2. cd

cd (Change Directory) is the command that we use to jump between directories. It is a simple command — just type cd followed by the name of the directory -

cd [directory]

As such, if you want to enter the home directory of your server, you can type -

cd home

You may also write the full path of a particular directory if it is a few levels below. For instance -

cd home/TestDirectory/AnotherDirectory

3. mkdir

You can work mkdir (Make Directory) command to create a directory. This is the syntax -

mkdir [folder name]

Let’s assume you want to create a new folder labeled “myfolder”. You will need to type -

mkdir myfolder

4. touch

This SSH command is applied to create a new file. Here is the syntax -

touch [file name]

If you want to create a .txt file named “myfile”, this is what you require to write -

touch myfile.txt.

The file extension could be anything you want. You can even produce a file with no extension at all.

5. rm

The rm command removes a chosen file or directory. To delete a file, enter -

rm [file name]

For instance, if you require to remove myfile.txt, simply execute -

rm myfile.txt

To delete a folder, you need to use the -r option to remove all the files and subfolders inside it -

rm -r home/hosting/myfolder

6. cat

We use the cat command to represent the content of a file. Below is the syntax -

cat [file name]

It also allows you to create a new file by joining multiple files. For example -

cat info.txt info2.txt > mergedinfo.text

By executing this line, the content of info.txt and info2.txt will be saved into mergedinfo.txt.

7. pwd

pwd is a simple command that outputs the whole track of your working directory. Once entered, you should view a result like this -

home/user/public_html

pwd command can come in handy when you are obtaining your shared hosting account through SSH.

8. cp

This SSH command will copy files and folders. The syntax is -

cp [options] [source] [destination]

[source] is the file or folder you want to copy and [destination] is the duplicate. Let’s say you have myfile.txt in your working directory, and you want to make a copy of it. The syntax would be -

cp myfile.txt myfile2.txt

If you want to make a copy in a different folder, run the following command -

cp /home/myfile.txt /home/etc/


9. mv

This command operates similarly to cp. However, the mv command will move the file or folder rather than copying it. This is the syntax -

mv [source] [destination]

Let’s say we want to move

myfile.txt from /home/ftp to /home/myfolder/.

The command should be -

mv /home/ftp/myfile.txt /home/myfolder

Unlike cp command, you don’t need the -R option to move a folder. For instance -

mv /home/ftp/ /home/myfolder/

This will automatically move all files and subfolders inside ftp to my folder.

10. grep

grep command views for a given string in files. For example -

grep 'line' info.txt

The above command would explore for ‘line’ in a file named “info.txt”. What a great, the command will print the whole line that includes the matched text. Keep in mind that this command is case-sensitive. If you want to ignore letter cases, use the -i option.

Last Words

This article includes "Best SSH Commands". Read the complete article and get information about ssh clients.