30+ Common SSH Putty Commands to Manage Your Server
Putty is an open source Windows OS based software to manage your hosting server remotely. Putty commands help you to log into your server and execute necessary operations. SSH access is also known as the most secure way to communicate with your machine remotely. There are a bunch of ssh commands for different purposes.
Recently, I bought unmanaged web hosting from Host1Plus to learn how SSH access works. Their cloud hosting plans come with multiple options like managed and unmanaged cloud hosting. You might know that in unmanaged hosting, you have to install everything yourself such as PHP, MySQL, Apache, etc.
Anyway, I planned to install WordPress and installed everything using Putty client. Here I am going to list some of the useful putty commands. So, you can easily understand and learn how to manage Linux server.
What is Putty?
Putty is a Windows-based open source software to communicate with your web server and execute commands. It was originally developed for Microsoft Windows and written by Simon Tatham on Jan. 8, 1999. Putty support multiple network protocols such as SSH, Telnet, rlogin, SCP, and Raw socket connection. You can also use it for Unix platforms.
You can transfer files, delete them, move, or copy files using necessary commands on your remote machine (server). All you have to do is learn basic commands and how to operate. It’s simple to use and doesn’t require advanced skills for basic stuff like copying or compressing etc.
How to Login using Putty in Linux Server?
First off, download the Putty software on your computer. It works out of the box; you just have to double click on the downloaded file. Accessing your Linux server requires the following details;
- Server IP address
- Port Number (*Usually 22)
*Port number can be different and vary on hosting provider. Like SiteGround their default port number is 18765 rather than 22. So, if you failed to login after adding all the information correctly then contact your hosting company and ask for the SFTP port number or just Google it. Chances are you’ll find it.
After getting all the above information, enter these credentials as I mentioned below in the image;
After a successful sign in, it will show you a black windows like below one and its time to get your hands dirty on ssh commands.
[[email protected] ~]$
Most Commonly Used Putty Commands to Manage Your Linux Server
Change directory (cd)
cd or change directory help you move from one directory to another. After typing cd, enter the directory name in which you want to navigate.
cd [directory name]
Example:[[email protected] ~]$ cd testfolder
Remain in the same folder (cd .)
Well, it is pretty useless and do anything. When you use it, it remains you in the same folder/directory.
Example:[[email protected] ~]$ cd .
Move to one step up (cd ..)
You can use the above command to move to the previous or one step up directory just by typing two dots like below.
Example:[[email protected] ~]$ cd..
Jum to home directory (cd ~)
This putty command helps you navigate to the home folder or directory of your server from any working location. For instance, your current directory is four folders deep from the home directory. Then use this command to go into the home folder.
Previous folder (cd -)
Go to the up/down directory from your current location.
Example:[[email protected] ~]$ cd –
Let’s say you are here; /root/askbebdg/testfolder/imrannazish/
And now if you want to navigate into “testfolder” then type “cd -” It will land you in one previous folder. Then typing again, it’ll move you to the one next folder which in this case will be “imrannazish”
Move to root of your server (cd /)
Using this putty command, you can straight head over to the root of your web server.
[[email protected] ~]$ cd /
This command quite useful when you’re located in deep directories and want to just land in the root directory of the server.
Note: There is a difference between “cd /” and “cd ~”.
Find current directory (pwd)
PWD or print working directory used to know the current directory.
It will show directory path something like this: /home/username/directory1/yourcurrentdirectory
In my case it is this one:
Files and Folders Management (Copy/Move)
Copy a file (cp)
Pretty clear, it helps you copy one or multiple files.
Example:[[email protected] ~]$ cp mthtest.php /root/testfolder/
For copying multiple files, all you have to do is type all the file names including their extension with single space between each file name, just like this;
cp [filanem1] [filename2] [filename3] /root/username/testfolder/
Example:[[email protected] ~]$ cp test1.php test2.php test3.php /root/username/foldername/
Force file copy (cp -f)
cp -f filename.php /root/username/yourfolder/
Example:[[email protected] ~]$ cp -f testfile.php /root/username/testfolder/
Copy and rename a file
cp filename /root/username/newfilename
Example:[[email protected] ~]$ cp testfile.php /root/username/testfolder/testfile2.php
Move a file from one place to another (mv)
mv filename.php /root/username/destinationfolder
Example:[[email protected] ~]$ mv header.php /root/testfolder/testfile.php
Here keep in mind, you should type the root address and directory name where you want to move the file. Otherwise, it won’t work.
Move and rename the file name
mv filename.php /root/destinationfolder/filename2.php
Example:[[email protected] ~]$ mv testfile.php /root/username/testfolder/testfile2.php
*testfile2.php is the new name of testfile.php file.
Move file one directory up
Use this ssh command line to transfer your file to one directory above.
mv filename.php ..
Example:[[email protected] ~]$ mv testfile.php ..
Checking Files and Folders
List all files and folders (ls)
ls is a short form of “list” and it shows you all the files and folders in your current directory. Just type ls and hit enter.
Show files with size (ls -ls)
Like above putty command, using this one, you can analyze each file with size in a large list format.
List all files within a folder (ls -lh)
This ssh syntax comes handy when it comes to check or list all files and folders in a required directory including their sizes and extensions.
ls -lh [foldername]
Example:[[email protected] ~]$ ls -lh testfolder
Check all files with folder (ls -a)
In case, we need to monitor all the files within a folder, this is where above syntax help you out.
List content by file size – from large to small (ls -S)
Create New Files and Folder
Create new folder (mkdir)
mkdir [folder name]
Example:[[email protected] ~]$ mkdir testfolder
Create new files with different extension (touch)
Example:[[email protected] ~]$ touch header.php
Delete Files and Folders
Remove files (rm)
It helps the users to delete any file from the server.
You can also delete multiple files at once using the below ssh syntax.
rm [filename1] [filename2] [filename3]
Example:[[email protected] ~]$ rm testfile.php
Example 2:[[email protected] ~]$ rm testfile.php testfile2.css testfile3.php
*testfile.php is the file name and .php is extension
Delete a directory (rmdir)
rmdir [directory name]
Example:[[email protected] ~]$ rmdir testfolder
Remove all file exists in a specific folder (rm *)
With this ssh command, you can delete all files within a folder.
Example:[[email protected] ~]$ rm *
Note: It doesn’t remove folders, only work for files. And you must go to the folder in which you’re going to run this command. Like if I need to destroy all files in “testfolder”, you must be present in that directory before executing this command line.
Compress/Uncompress Files and Folders [done]
Compress file or folder (zip)
zip -r [zipfilename.zip] [filename]
Example:[[email protected] ~]$ zip -r testfile.zip testfile.php
- testfile.zip is the name of compressed format version of testfile.php. You can type your desired name as per your ease.
Now, compressing a folder is also same as file, all you have to do is type folder name just like file.
Example:[[email protected] ~]$ zip -r testfolder.zip testfolder
Un-compress zip files (unzip)
Example:[[email protected] ~]$ unzip testfile.zip
or if wish to extract in a specific folder then type that address such as /home/username/testfolder/
Compress/Uncompress file and folder in tar.gz format
Compress with tar.gz format
tar -czvf filename.tar.gz filename[[email protected] ~]$ tar -czvf testfile.tar.gz testfile.php
Same way you can extract folders as well.
Uncompress tar.gz formatted files
tar -xvf filename
Example:[[email protected] ~]$ tar -xvf testfile.tar.gz
Putty Command for Changing Permissions
Change the permissions for individual file
To modify the permission for single file use this;
cdmod [permission access] [filename]
chmod 745 testfile.php
Change the permission for folder and all of its Files
Now, if you want to modify the permission for a folder and all its files then;
chmod [permission access] [foldername] [-R] [code] Example: [[email protected] ~]$ chmod 724 testfolder -R Server Informational SSH Commands Find your username [code] [[email protected] ~]$ whoami
Find the activities or network statistics of your server
[[email protected] ~]$ netstat
Check your server CPU statistics
You can exit by typing "q".
Check memory usage of your server
Well, these are some commonly used ssh commands to maintain Linux based server. I hope this tutorial will help you manage your content or at least teach something new about Linux. If you think I have missed any putty command which is commonly used and should be listed here, please suggest in the comments section below.