List of Basic SSH(Secure Shell) Commands
Secure Shell (SSH) is a widely used protocol for secure remote access and system management. With SSH, users can securely connect to remote servers, execute commands, transfer files, and perform administrative tasks.
This article provides a comprehensive list of basic SSH commands that will empower you to navigate through remote systems, transfer files securely, and execute essential administrative tasks.
By understanding these commands, you’ll gain the ability to securely connect to remote servers, configure settings, and transfer files, all while ensuring the privacy and integrity of your data through SSH’s robust encryption techniques.
Understanding SSH
SSH, short for Secure Shell, is a cryptographic network protocol that facilitates secure communication between a local and a remote computer. It provides a secure alternative to traditional remote login protocols like Telnet, which transmit data in plain text, making them susceptible to eavesdropping and unauthorized access.
SSH employs strong encryption algorithms and offers various authentication methods to ensure the confidentiality and integrity of data transmitted over the network. By establishing a secure connection, SSH enables users to access remote systems and execute commands securely, even over an untrusted network such as the Internet.
The Importance of SSH Commands
SSH Commands form the foundation of secure remote administration. They allow users to interact with remote systems, execute tasks, and manage files seamlessly. Whether you need to remotely configure servers, transfer files securely, or troubleshoot network issues, mastering basic SSH commands is essential.
In this article, we’ll walk you through a selection of core SSH commands that will empower you to perform a wide range of tasks, from establishing secure connections to managing files, and even tunneling network traffic.
Now, without further ado, let’s explore the fundamental SSH commands that will unlock the potential of secure remote communication and administration.
Download PuTTY Now!
Command
pwd
Function
As soon as you are logged into the server, the first and foremost thing to check would be the present location you are at. The command “pwd” takes care of that. Just type “pwd” and hit enter.
Command
cd
Function
Now, you are at a location and you want to navigate to another. Type “cd /location” and you will reach that location. It stands for “change directory”.
Type
- “cd .” makes you stay in the same directory you are in
- “cd ..” makes you shift one directory back. For example, you are at “/home/task/files” and you type “cd..” and hit enter. This will move you to “home/task”
- “cd -” makes you go to the previous location you were at. For example, you were at “/home” but you moved to “/dir”
- Typing “cd-” command will take you back to “/home”
- “cd ~” will take you to your home directory
- “cd /” will take you to the root directory
Command
mkdir
Function
It stands for make a directory and as the name suggests, it helps you with making a new directory with the name you choose at your current directory path.Syntax: mkdir directoryName
Command
ls
Function
It stands for list command which is used to display all the contents in a folder or directory. “ls /home/folder” will enlist all the content inside the “folder” directory.
Type
- “ls -a” will show you all the files in a directory”
- “ls –h” will show the files while showing their sizes as well.
- “ls -r” will recursively show the subdirectories of the directory
- “ls -alh” will show you more details about the files contained in a folder. The details include the user permissions, last updated date, date of creation, time, and the permission allotted to it like read, write, and update.
Command
cp
Function
It stands for copy command that basically copies a file in Linux.Syntax: cp filename.extension /dir/filename.extensionThe above command will copy the file “filename.extension” (source) and keep it to the location /dir (destination) with the same file name.
Type
- “cp -r” copies all the contents of a folder.
- To copy and rename, use the command “cp filename.extension/dir/filename1.extension”. The file “filename.extension” will be copied to “filename1.extension present at /dir location.
- “cp -f” will force the copy process by deleting the destination file if a file with the same name happens to be there at the destination.
- “cp -i” will give you a warning message before actually proceeding with the copying process.
- “cp –u” will update the file in the destination folder only if the files have different content.
- “cp –n” will first check if the file already exists and if it does, it just won’t copy. It doesn’t overwrite the file.
- “cp -a” will archive the file
Download PuTTY Now!
Command
mv
Function
- The move command moves the file from one place to another instead of copying it, leaving no signs of the file in the source folder
- Syntax: mv filename.extension /dir/filename.extension
- To move and rename a file, use the command “mv filename.extension /dir/filename1.extension”
- You can also move your file one folder back by using the command “mv filename/ .
Command
touch
Function
Using “touch” command, you can create a new file with any extension you want like text, php, html, etc in your current directory. You can also create a file without any extension at all.Syntax: touch filename.extension
Command
rm
Function
The remove command lets you delete a file from the server.Syntax: rm filename.extension
Type
- “rm * foldername” will delete all the files or content in a directory.
- “rmdir” will remove the complete directory or folder.
- “rm -r foldername” will delete the folder as well as the folders inside it
Command
cat
Function
This command is used to display content of a file on the screen. It copies standard input to standard output. This command also allows scrolling if the displayed text doesn’t fit the screen completely.Syntax: cat filename.extension
Type
The cat command is also used to concatenate two files and show their content combined as one.
- Syntax: cat file1.txt file2.txt > mergedfile.txt “>” is the output redirection character
- The cat command can also be used to create a new file. Syntax: cat > filename.extens
Command
head
Function
The head command lets you read the first ten lines of the content inside a file.Syntax: head filename.extension
Type
You can also give the names of more than one file in the head command and it will show the first ten lines of each file separately.
- Syntax: head /dir/file1 /var/file2
You can also change the number of lines you want to be displayed on the screen rather than the default first ten lines.
- Syntax: head -n15 /temp/filena
Download PuTTY Now!
Command
tail
Function
Just like the head command gives you the first ten lines, tail command gives you the last ten lines of content from the file.Syntax: tail filename.extension
Type
Also, you can provide multiple file names to the tail command for it to show last ten lines from each of the mentioned file.
- Syntax: tail /dir/file1 /dir/file2
Similar to the head command, the tail command also allows you to change the number of lines you want to be displayed other than the default number.
- Syntax: tail -n15 /temp/filena
Command
zip
Function
A compression and file packaging utility in unix, zip command compression the file size. It also puts one or more files into a single zip archive.Syntax: zip -r foldername.zip foldername
Type
- Using the command “zip -d filename.zip filename”, you can delete the file from the zip archive
- Using the command “zip -u filename.zip filename”, the specified list of files can be updated in the zip archive
- “zip -m filename.zip filename” deletes the original file after creating its zip archive
Command
unzip
Function
The unzip command is used to decompress a file.Syntax: unzip filename.zip
Type
You can unzip multiple numbers of files at a time by using the command
- “unzip file1.zip file2.zip file3.zip”
You can also exclude one or more files from unzipping
- Syntax: unzip filename.zip -x excludedfile.z
Command
tar
Function
It stands for tape archive. Also used to compress and decompress folders.Syntax: Command for compressing, that creates an archive for “folder”.tar -czvf folder1.tar.gz folder The command for decompressing tar -xvf folder1.tar.gz
Command
chmod
Function
chmod stands for change mode. Using this command, you can change the permissions of a file or directory. These permissions can be represented either by numbers from 0 to 7 or with alphanumeric characters. 4 represents reading permission, 2 represents writing permission, 1 represents executing permission and 0 represents no permission.Syntax: chmod 7,5,4 filename
Type
- In the above command, 7,5,4 represents the permission for the user, group, and others wherein 7 is the combination of 4,2 and 1, which indicates all the three permissions are given to the user.
- Similarly, 5 is the combination of 4, 0, and 1, which indicates read, no write and execute permission.
- Also, 4 is the combination of 4, 0, and 0, which indicates read, no write and no execute permission. “chmod -r” lets you change the permission of a folder and all the files inside it as well.
Download PuTTY Now!
Command
grep
Function
If you want to search for a particular string inside a file or folder, grep is the right command for you. It returns the whole line containing the phrase if it finds the perfect match.
Syntax: grep “string” filenam
Type
- Option i in the command “grep -i “string” filename” lets you search for a string case-insensitively in the file
- You can count the number of appearances of a string in the given file by using the command “grep -c “string” filename”
- You can display the filename that contains a particular pattern or string using the command “grep -l “string” *”
- You can also display the line number along with the result using the command “grep -n “string” filename”
Command
find
Function
This command searches for a file inside a folder. Files with specific criteria can also be filtered out using this command. You can run find command to find files by permissions, users, groups, file type, size etc.Syntax: find . -name filename.extensionThe above command will find all the files with the name “filename.extension” in the current directory.
Type
- If you want to find a file in some directory, use the command “find /directory -name filename.extension”.
- You can look for any type of file, say a php file by using the command “find . type f -name filename.php”
Command
vi
Function
The vi command lets you enter a text editor.Syntax: vi filename The above command will open the file on the screen and if the file doesn’t exist, it will create a new one with the same name. The escape key lets you cancel any command you have started in the vi editor mode. To exit the vi editor, type “:q”, only if you haven’t done any changes to the file. If you want to discard the changes you have done to the file, type “:q!” to
So, these are some of the Basic SSH (PuTTY) Commands that come in very handy for a user to manage the basic functionalities and handle files and folders on a Linux web server.