Computers

How to manage your web server via SSH (Part 1)

If you are new to the web hosting industry you must be using one of the control panels provided by your hosting provider, such as cPanel, Plesk or a native web UI from your hosting provider. But if you are to get the full advantage of your hosting service you might want to do you own customizations, performance tuneups, etc..

Since there are limitations to what you can do with your control panel most of the hosting providers give full access or limited access to your portion if its a shared hosting. The technique used to connect securely to your Linux server is SSH because it has a lot of security features running under the hood.

If you have not connected to a server via SSH, Please go ahead and read this article on connect to your web server via SSH

Once you get there try the following commands and get familiar with the Linux environment.

How to know where you are

Type ‘pwd’ without quotes and press enter or return on your keyboard and this is the command used to Print Working Directory (pwd).
If you are moving from Windows environment you must be having a doubt on how this file structure is organized since you wont be finding a drive letter as a prefix to the directories. Instead you will find ./ which is also called the root directory.

List what is inside your current directory

Type ‘ls’ without quotes and hit enter or return. This will list all the files in your current directory, and you can always customize your commands by adding parameters towards the end. E.g.: try ‘ls -l’ without quotes to get a list of available files on your current directory with¬† additional information.

Go into a directory

You can do this by typing ‘cd’ followed by the directory name without quotes. E.g.: Lets say you got a directory named Desktop when you type ‘ls -l’ you can type ‘cd Desktop’ to move into that directory.
or if you know the full path of the directory you can type it directly to switch directories. E.g.: Try ‘cd /var/www/’ without quotes. This should lead you to the web hosting folder and list the files as how it looks like when you login with your FTP account. If you are on shared hosting this might be in ‘/home/username/domainname.com’
Try ‘cd ..’ without quotes to go one level up in your directory.
Try ‘cd ~’ without quotes to go to your home directory.

Copying Files

You can copy files with the ‘cp filename.ext /destination/filename.ext’ without quotes. How this work is you type cp followed by the file you want to copy, and then the destination and the name you want it to appear as.
If you have successfully managed to get into the site directory you can try this buy performing actions like ‘cp logo.jpg /images/logo.jpg’ or ‘cp index.html test.html’

Move Files

Try ‘mv filename.ext /destination/filename.ext’. This is very much similar to copy function, except that the original file will be deleted after copying to the destination.
You can use this also to rename files.

To view a file

Try ‘cat filename.ext’ without quotes to view the files. However, this can be hard if you have a large file. In that case, you can use ‘less filename.ext’ or ‘cat filename.ext | more’ to conveniently scroll through the content. Less uses the arrow keys, and more command use Enter to move to next page. At any point you can press ‘q’ to exit from the file.

If you can efficiently make use of these commands I’m sure you will begin to like your SSH connection more than your FTP. We will discuss more about the variations to these basic commands in later articles.

Share this post

Related Posts