SSH Commands

0
168
SSH Commands

Today many companies focus on the security of their data. Most companies do not have a secured network but want to access a system securely, and for that, they need a network protocol. SSH, which stands for Secure Shell, provides a secure network to connect one system with another. Also, SSH not only offers secured network services but also helps in implementing the SSH protocols.

Two systems that want to communicate over an unsecured network require a way to secure the network which SSH provides via strong password encryption and public-key encryption. The system administrators commonly use SSH for managing systems and log into them remotely. You can also run SSH commands on the remote system to execute various tasks.

Through this article, you will learn about SSH, its use cases, and various SSH commands that can be run on the remote system.

Cheap SSL

What is SSH?

SSH basically refers to the cryptographic network protocol and the utility bundle that helps implement the protocol. SSH is based on the client-server model, where the client system connects to the server system using an application. With SSH, you do not have to have physical access to the system and can seamlessly connect to it over the network.

It was first introduced in the mid-90s and was designed to replace the Telnet that transfers data without encryption. However, in the absence of encryption, the data being transferred can be hacked and tracked easily by hackers. With SSH, you can see that data is getting transferred and the amount of data, but cannot interpret the data.

Use Cases for SSH Protocol

SSH connection can be used to secure different types of communication between a local system and a remote system. Here’s what SSH protocol allows you:

  • Accessing the remote resources securely.
  • Executing the commands remotely.
  • Securely delivering the software patches and updates.
  • Transferring the interactive and automated files.

SSH creates a secure channel for communication and manages critical corporate infrastructure like routers, hardware, virtual platforms, and OS. Moreover, SSH helps in automating the access to various servers using scripts.

Accessing Remote Server

Before you can execute SSH commands, you need to access the remote server. For that, you will require an SSH client (PuTTY). You need to install and open it on your system, and then perform the following steps:

To connect to the server, you need to provide details like the IP address of the server and the port number. Then click open to open the remote system.

You can also run the following command in command prompt (Windows) or terminal (Linux and macOS) to enter the remote server:

ssh user@serverip

Here user is the user name and serverip is the shared IP address.

Once you click open or run the above-mentioned command, you will be asked for a password. You need to enter the password to log in to the remote server.

Various SSH Commands

Below are the basic SSH commands that can be run on the remote server to carry out various tasks.

1. Checking working directory path

To check the path for the working directory, you can run the ‘pwd’ command on the terminal. You will get the result as shown below in the image:

2. Changing directory

If you want to check or display the content of the current working directory, you need to run the ‘ls’ command. You will get a list of all the files, directories, and links present in that directory. To get more information about a directory, you can use the various flags mentioned below:

  • -a flag will help in displaying the hidden files starting with a dot.
  • -l flag will help in showing file details for every directory’s contents like permissions, ownership, date, etc.
  • The -s flag will list the size of all available files in blocks.
  • You can even add a ‘-h’ flag to see the size of the files in a humanly readable form.

If you want to go to a specific folder, you can use the ‘cd’ command with a name or the path for the folder, as shown below:

cd Desktop/Downloads/Sample

You need to make sure that the folder name is entered correctly; the folder name you enter is case-sensitive. The ‘cd’ command comes with various options like:

  • cd .. helps you to navigate to the directory one level higher than your current working location.
  • cd – will help you switch to the previous directory.
  • cd / will navigate you to the root directory.

3. Copying a file

If you want to copy a file from one location to another, you can use the ‘cp’ command. With this command, you will have to provide the file name and the target location.

cp fileName /directory/path/destination

If you want to change the name of the file during the copy command, you can use the below command:

cp file1 Dir1/Newfile1Name

The above command will copy the file ‘file1’ to the specified directory with the changed name ‘Newfile1Name’.

To copy the directory and its content, you can use the ‘-r’ flag as shown below:

cp -r Directory1 NewLocation

4. Moving a file

You can move a file from one location to another by using the command mentioned as follows:

mv fileName directory/path/destination

5. Creating a file

You can run the following command to create a new file with any extension in the current working directory:

touch fileName

6. Creating a directory

If you want to create a directory within the current working directory or the mentioned path, you can run the ‘mkdir’ command as shown below:

mkdir NewDirectory

Or:

mkdir directory/path/NewDirectory

7. Deleting a file or directory

If you want to delete a particular file or directory, you have to run the ‘rm’ command as mentioned below:

rm fileName

If you want to provide the complete path for the file to be deleted, you can do it like this:

rm /home/user/dir1/fileName

You need to add the ‘-r’ flag with the rm command to delete a directory.

8. Checking network information

If you want to check the status of all the network adapters, you can run the ‘ipconfig’ command as shown below in the image:

9. Checking the content of a file

If you want to display or list down the content of the file on the terminal, you can use the ‘cat’ command:

cat [file name]

You can also merge various files into one file with the cat command as shown below:

cat info.txt info2.txt > mergedinfo.text

10. Grep command

You can look for a particular string in the files using the ‘grep’ command, as shown below:

grep ‘line’ info.txt

The above command will search the file name and return the complete line that contains the ‘line’ string.

11. Clearing the terminal

If you want to clear the working area, then you can run the ‘clear’ command on your terminal.

12. Checking disk usage

If you want to check the disk usage, like the size of the file and folders in a specific directory, you can run the ‘du’ command as shown below:

du [directory path]

If you want to see the results in human-readable format, you need to use the ‘-h’ flag with the ‘du’ command:

du -h /home

Conclusion

SSH is a very secure way of communicating with a remote system over a network. It works on the client-server model with strong encryption. You can carry out various tasks using SSH commands. In the above article, we have mentioned several basic SSH commands that you must learn before logging into any remote server using SSH.

People are also reading:

LEAVE A REPLY

Please enter your comment!
Please enter your name here