Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  Must Know Secure Shell Commands For System Security
Top Scroll

Must Know Secure Shell Commands For System Security

 5 min

SSH is an abbreviation for Secure Shell, which is a valuable tool for securely accessing and managing remote servers. Even if you’re a newcomer or a seasoned professional, learning these most commonly used secure shell commands will improve your productivity and expertise in effectively handling your servers.

Let’s unfurl the Secure Shell (SSH) commands that every user must need to know: 

Key Secure Shell Commands

SSH, Secure Shell, or Secure Socket Shell is a network communication protocol that facilitates communication between two devices. This encrypted connection can also be utilized for file transfers, terminal access, and application tunneling. 

Basic SSH Commands With Description: 

Secure Shell Command (SSH)Description
lsShow directory contents, i.e., list all file names.
cdChange directory.
mkdirCreate a new folder or directory.
touchCreate a new file.
rmRemove a file.
catShow the contents of a file.
pwdShow the current directory. It shows your full path to where you are right now.
cpCopy a file or folder.
mvMove a file or folder.
grepLook for a particular phrase or string in the file or lines.

1. Is Command

This Secure Shell command is utilized to show the directory contents or, in other words, list all the files and directories.

Syntax: ls [options] [paths]

You can combine the ls command with a few useful options: 

  • -l —  It shows file details, like size, last updated date and time, the owner, and the permissions.
  • -a —  It shows all the files together with hidden files in the respective directory.

2. cd Command

cd command stands for Change Directory. This simple SSH command is used to navigate between directories. You just have to enter cd followed by the directory name:

Syntax: cd [directory]

  • If you wish to navigate to your server’s home directory, you can type the following command: 
cd /home
  • You can also enter the complete path of a specific directory, irrespective of its hierarchical depth. For example:
cd /home/TestingDirectory/AnotherTestingDirectory

Thus, you’re now inside the AnotherTestingDirectory.

  • If you want to go back one level, just enter two dots ( “..”) after the cd command. Similarly, if you enter two more dots and separate them with a forward slash (“/”), you’ll be able to go back further:
cd ../..

After entering this command, you’ll be back in the home directory again.

3. mkdir Command

A mkdir SSH command is used for making a new directory. 

Syntax: mkdir [folder name]

Assume that you wish to create a new directory named “myfirstdirectory,” then the command will be:

mkdir myfirstfolder

4. touch Command

A touch command is useful when you wish to create a new file.

Syntax: touch [file name]

Assume that you wish to create a new text file named “myfirstfile,” then you’ll have to enter the following command: 

touch myfirstfile.txt.

You can choose any file extension you want or you can create a new file with no extension.

5. rm Command

The rm Secure Shell command is used for removing a specific file or directory. 

Syntax: rm [file name]

  • For example, assume that you wish to remove myfirstfile.txt. Then simply run the following command: 
rm myfirstfile.txt
  • If you want to remove a directory,  then add the “-r” option with the rm command to remove all the files and subfolders within it: 
rm -r home/milesweb/myfirstfolder

6. cat Command

A cat command is used to show the content of a file. 

Syntax: cat [file name]

  • This SSH command also enables you to create a new file by combining several files: 
cat info1.txt info2.txt > info3.txt

The above command will store all the data present inside both the info1.txt as well as info2.txt files in a newly created info3.txt file.

7. pwd Command

pwd is a simple Secure Shell command that displays the complete path of your current working directory. 

Syntax: pwd

After entering the pwd command, you’ll see an output like this: 

home/user1/public_html

Most of the time, shared hosting servers don’t show the current working directory you’re in. This is where a pwd command is helpful. 

8. cp Command

A cp command is used to copy files and folders. 

Syntax: cp [options] [source] [destination]

Here,

  • Source file – refers to the file or directory for copying.
  • Destination file – it doesn’t exist, but the cp command creates it by copying the entire content of the source file into it. 

For example, assume that you’ve got a file named “myfirstfile.txt” in your current directory and you wish to make a copy of it. Then enter the following command:

cp myfirstfile.txt myfirstfile2.txt
  • To make a copy in another folder, use the following command:
cp /home/milesweb/myfirstfile.txt /home/etc/

Be mindful when entering the name of the destination file or folder. If you put two file or folder names, then, as you know, a cp command copies the content of the source file into the destination file. In this case, the destination file will be overwritten without prior notification. But having said that, if the destination file isn’t available, then the cp command will create a new file. 

9. mv Command

A mv command works the same as the cp command, but the mv command will move the respective file or folder rather than copying it. 

Syntax: mv [source] [destination]

Assume that you want to move myfirstfile.txt from /home/milesweb/ftp to /home/milesweb/myfirstfolder/. Then, you must enter: 

mv /home/milesweb/ftp/myfirstfile.txt /home/milesweb/myfirstfolder
  • Contrary to the cp command, you won’t require the “-r” option to move a file or folder. For example:
mv /home/milesweb/ftp/ /home/milesweb/myfirstfolder/ 

The above command will automatically move all the files and subdirectories within the ftp folder to myfirstfolder. 

10. grep Command

A grep command is used to find the given string in the files.

Syntax: grep [search_word] [file_name]

For instance, assume that you want to look for the term “hosting” in the “info1.txt” file. Then the command will be: 

grep 'hosting’ info1.txt

The above command will look for ‘hosting’ in a text file named “info1.txt.” As an output, it’ll print the complete sentence that contains the matched string.

Remember that the grep command is case-sensitive and if you wish to ignore the lettercases, then use the “-i” option with it.

Conclusion

Mastering Secure Shell (SSH) commands is important for effortlessly managing Linux servers and it’s the most efficient method to browse through your system device and make changes to files and folders.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.