Basic SSH (PuTTY) commands help you to navigate and work efficiently with the files in the Linux terminal. In this article, We’d handpicked a list of PuTTY commands, their options, and usage.
What is SSH (PuTTY) Commands?
The Secure Shell (SSH) Protocol lets a user connect to a remotely located computer from one computer. This communication takes place through a secured encryption process. This kind of connection can be used for file transfer and issuing other remote commands. The SSH Protocol follows a client-server model in which a connection is established by SSH Client to the SSH server. The SSH client uses public-key cryptography to ensure a safe connection to the SSH server. After setting up the connection, the SSH client also ensures that the privacy and integrity of data are maintained throughout the network by using symmetric encryption, asymmetric encryption, and hashing algorithms.
The client-server based model of SSH commands or PuTTY commands allows the authentication of two remotely located systems while encrypting the data that passes through them. By default, SSH operates on TCP port 22, but it can be changed if required. The client connects with the server by performing a TCP handshake with the server, which is for verifying whether the information provided by the user matches with the previous record of information that is stored in an RSA key store file. Before establishing a connection, both the client and the server have to agree upon the encryption standards to ensure safe and secure communication, and then the user must perform the authentication check.
Now, to make use of PuTTY commands, a terminal emulator that connects the client to the server is required. PuTTY is one such emulator which is open-source and free to download. Also, windows don’t have a pre-installed SSH server or client. So, the prerequisites for being able to use SSH (PuTTY) commands are as follows:
- A Linux based server that you would be connecting to.
- PuTTY for facilitating the connection process.
- The server’s IP address that acts as the location of the server to which you are trying to connect.
- Username and Password to make sure that you are authorized to connect to the server.
Connecting through PuTTY
- To connect to the server, enter the IP address of the server to the Host Name or IP address bar as shown in the image and keep the port as 22 and connection type as SSH. You may also save the configuration for further use.
- The PuTTY terminal will now open, asking for a username and password to connect.
- You will be logged on the server you are trying to make a connection to.
If you using a Linux or Mac-based Operating System, you don’t need a client like PuTTY as Linux has its own SSH terminal. You just need to use the following command to connect to the server:
This command will connect you to a server whose IP address is “server”. “User” is the username that is authorized to connect to the server.
Upon entering the above command, you will be prompted to enter the password.
To close the connection to the remote server, just type “exit” on the terminal window. It will get you back to your local machine.
List of Basic PuTTY Commands
Now, to manage and operate on a Linux server, one must master the basic 18 SSH commands to make the most use out of it. Let us look into some of the basic commands of SSH communication.
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.
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”.
- “cd .” makes you stay at the same directory you are at.
- “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 the “cd-” command will take you back to “/home”.
- “cd ~” will take you to your home directory and “cd /” will take you to the root directory.
It stands for make 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
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.
- “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.
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.
- “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.
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/ ..”.
Using the “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
The remove command lets you delete a file from the server.Syntax: rm filename. extension
- “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.
This command is used to display the 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
- 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.extension
The head command lets you read the first ten lines of the content inside a file.Syntax: head filename.extension
- 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/filename
The above command will display the first fifteen lines of content from the given file.
Just like the head command gives you the first ten lines, the tail command gives you the last ten lines of content from the file.Syntax: tail filename.extension
- Also, you can provide multiple filenames to the tail command for it to show the last ten lines from each of the mentioned files. 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/filename
The above command will display the last fifteen lines of content from the given file.
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
- 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.
The unzip command is used to decompress a file. Syntax: unzip filename.zip
- 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.zip
The above command will extract all the files from the compressed archive except excludefile.zip.
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 command for decompressing
tar -xvf folder1.tar.gz
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 754 filename
- 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.
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” filename
- The 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”.
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. extension above command will find all the files with the name “filename.extension” in the current directory.
- 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”.
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 exit.
So, these are some of the basic SSH (PuTTY) commands that come very handy for a user to manage the basic functionalities and handle files and folders on a Linux web server.