Linux SSH commands to show and monitor server resources and real-time performance: memory, swap, disk usage, CPU usage and I/O …

Below are a few general commands found in most popular Linux distros which you can use via SSH to check the status of your hosting server.

To show used and available RAM memory and swap space usage:

free -m

To show current disk storage usage by mounted device:

df

To show disk usage statistics of the current directory by directories and files:

du

To show the hard disk space a directory or a file takes up:

du filename

To show the length of time this server has been up and the server loads in the past 1 minute, 5 minutes and 15 minutes:

uptime

To display a real-time updated server resource usage including: server uptime, user logged on, load average, current tasks, CPU usage, memory usage and swap usage:

top

To display a list of real-time active or sleeping processes your server is up to:

ps

To show some information about the current status of virtual memory, CPU usage, I/O usage:

vmstat

This is also a good tool to find out system performance bottlenecks.

To display currently logged on users on the system:

w

Or

who

To print a full screen text graph of the server load refreshed every few seconds:

tload

If you are on shared hosting, chances are your server usage has been imposed some hard limits such as the largest amount of files / directories possible and the hard storage limit. View them by:

quota

Comments ( 1 )

Typical iptables Firewall Rules for a Server that Hosts Websites

iptables is a rather handy tool to protect your server from unwanted and potentially malicious connection attempts. To list the current rules, run in SSH:

iptables -L

A typical set of firewall rules set by iptables on a simple server, be it VPS or dedicated, for hosting and serving websites should be like this:

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 8001,8002,8003,8004,8005,8006,8007,8008,8009,8010 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
iptables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT

Which enables

  1. ports 80 and 443 for web pages serving via HTTP and HTTPS
  2. port 21 and a series of tcp ports for FTP (passive mode) so that you can upload stuff to the server with your favorite FTP client
  3. port 22 for SSH access which can be modified for more security. If you have altered the default SSH connection port 22 to a random one, make sure you also change the port in the iptables rules set accordingly or the server will reject you.
  4. port 3306 for MySQL database server. Note that you may or may not need to open port 3306 for MySQL. For example, if you use ‘localhost’ as database server, there’d be no need most of the time.

And disables everything else.

These commands will only be in effect for the current session, once the server is restarted, all rules will be lost. In order to save these rules and make the server automatically load and apply them every time you reboot, write them into a file to be loaded upon every system start. Run:

iptables-save > /etc/iptables.up.rules

Command iptables-save saves the rule set to the file /etc/iptables.up.rules from the memory. Now configure the server to read and apply the rule set file /etc/iptables.up.rules every time it starts:

nano /etc/network/interfaces

And add a line immediately below ‘iface lo inet loopback’:

pre-up iptables-restore < /etc/iptables.up.rules

Now you are set. Reboot the server and see if all takes effect.

Comments ( 1 )

Customize or change the default SSH port 22 to a random custom one of your choice

By default, all newly set up servers listen and accept SSH login on port 22 which is known universally. To make it a little harder for hackers to break into your user account, one of the first steps you want to take is to change the default SSH port to a different on that’s randomly chosen by you.

To do this, simply modify the sshd configuration file by:

nano /etc/sshd/sshd_config

For novice SSH users, nano is more intuitive than vi. After loading the file in the editor, find and change this line:

Port 22

To

Port 8433

Ctrl + o and ctrl + x should save the change and get you out of the editor.

The port number can be anything between 1024 and 65535, inclusive. You can make it instantly in effect by reloading the new configurations:

/etc/init.d/ssh reload

Now the server will only accept SSH accesses on the port 8433. After modifying this, make sure you also change the remote port setting in your local SSH client or it will be rejected by the hosting server.

Comments ( 2 )

How to Change Login Password of Linux SSH User Account?

If you are root, you can change anyone’s password by:

passwd someuser

Wherein someuser is the user name of the account. It will prompt you to enter the new password twice.

If you are yourself and logged in with your own SSH account, you can also change your own password by simply:

passwd

It will also ask you to type your new password twice. Now you can log into your SSH with the new password.

Comments ( 1 )

Quick tip: 256 MB VPS helps you no more than shared hosting

256MB being the startup plan from most VPS providers will be no better than a shared hosting plan from affordable hosting providers. 384MB may seem to be a 128MB extra but actually just slightly more.

As a result of the nature of VPS, an entire operating system (such as Linux distributions: Ubuntu, Debian or Centos, and so forth) resides in it with a complete web server package: Apache, PHP, MySQL and potentially a lot of necessary modules and extensions, making the mere hosting slice of 256MB a frugal choice to cover all the overheads, much like the sunk cost in Economics. It is after the threshold of 256MB that every additional MB of RAM you purchase will be consumed by your own websites rather than by the system. Well, not precisely all of 256MB will be used for the system, but you are left with like 50MB – 100MB from the whole 256MB pie after installing everything WWW and getting your slice ready for websites.

So if you are going to switch to a VPS, make sure you board on at least 512MB memeory for a start or it won’t be worth the while and it may just be good enough to spread your sites across various shared hosting plans (preferrably from various distant hosting comapnies) for some SEO advantage.

Comments ( 2 )

$25 Rackspace Cloud Coupon and Referral Code for Rackspace Cloud Sites Hosting

mosso cloud hostingCrucial Update: The promo code (Code ID=134) as well as the $25 discount promotion will be ended by March 18th, 2010 by Rackspace Cloud. If you are still making up the mind to sign up with them, now is the time.

Activate Promo Code (ID=134) at RackspaceCloud.com »

Mosso (now Rackspace cloud) is probably the only hosting business that’s completely on a monthly subscription model, no discount incentives or whatsoever to lure you into yearly contracts, enabling its customers to leave anytime they want.

After some talk with Rackspace cloud, Shanghai Web Hosting is delighted to present our readers with a special Rackspace Cloud coupon code or referral code for the Cloud Sites hosting plan:

(Claim Code) click to activate, ID=134

This permanent Rackspace referral coupon code will guarantee a $25 discount (rebate / refund after full payment) from the first month at Mosso, now the RackSpace Cloud hosting. Just enter the code in the Promo or Referral Code text box when supplying your credit card details.

You don’t need to worry about the refund policy as well, because you can still qualify for a full refund for the 1st month after using this coupon code for Rackspace Cloud Sites.

See RackspaceCloud.com Promo (ID=134) »

To know why Rackspace cloud is unique, read our article about Rackspace cloud and the coupon or read a few customer reviews.

Comments Off on $25 Rackspace Cloud Coupon and Referral Code for Rackspace Cloud Sites Hosting

How to know whether your host is overselling?

Take on a trial which DreamHost offers or ask a friend at some hosting company to do some tests on SSH:

  1. Check for the number of server processors or CPUs
  2. Check for the average load the server is experiencing

Get the 3 load average figures divided by the number of CPU they have on the server, add them up and further divide them by 3. With the final result:

  • result <= 1 ( definitely an honest and great host)
  • 1 < result <= 2 (good one, but questionable)
  • 2 < result <= 5 (overselling, overselling, overselling, …)
  • result > 5 (are you crazy?!)
Comments ( 1 )

Check for Hosting Server Load with Linux (SSH) Command ‘uptime’

Some of the hosting providers out there are infamous for overselling who try their best to stuff in as many users (websites) as possible into a single web hosting server. High server load is an indicator of how your server is performing and whether it is laboring too much thus jeopardizing the performance of your websites. You can get to know the average load in the last 15 minutes of your server by the simple Linux command below (via SSH):

uptime

Which will typically return a line of data similar to this:

21:39:33 up 10:45, 3 users, load average: 4.46, 3.92, 3.64

That says there are currently 3 users logged on and the load average of this server in the last minute, last 5 minutes and last 15 minutes are 4.46, 3.92 and 3.64. These figures represent the number of runnable processes at the same time on average for the CPUs (processor) to process. Combined with number of processors of the server, you may know how many processes are being processed by any single CPU.

Considering the fact that any CPU can only take on one process at any given time, there will possibly be processes waiting in the queue – meaning server is overloaded. Therefore, if the number of processors of your hosting server is 4, in the last minute, it is overloaded by ( 4.46 / 4 ) – 100% = 11.5%.

Comments ( 3 )

Simple SSH (Linux) Command to Display the Number of CPUs (Processors) of Your Hosting Server

One of the first things that may concern you is that whether your web hosting company has equipped enough CPUs or Processors on your server as they have allegedly done. Or you are on shared plans and are simply curious whether your web hosting provider is overselling by overloading your server a lot.

First make sure you have SSH access to your hosting server which majority of hosting businesses are now providing. Then create an SSH account and log it in to the server.

A rather simple linux bash command will help you determine how many CPUs your host has on your server:

cat /proc/cpuinfo | grep processor | wc -l

This combination of pipeline command extracts server processors information from /proc/cpuinfo that contains CPU details each per line, returning a plain number which will usually be 1, 2, 4 or even more.

There you go. Now find out whether your host is cheating on you with this tip in addition to checking your server load! 😉

Extra Tips

You can find plenty of other useful and interesting information about your hosting server and OS release at /proc. For example, for some RAM stats:

cat /proc/meminfo

For total seconds since the last reboot:

cat /proc/uptime

For Linux release and versions:

cat /proc/version

And much more. Just ‘ls /proc’ and try for yourself.

Comments ( 6 )

Web Hosting Coupons: DreamHost Promo Code

Use DreamHost promo code: CASH60 signing up at here to qualify for an instant discount of $60.

DreamHost is undoubtedly the most trustworthy hosting provider in the affordable web hosting sector. Read an in-depth review about DreamHost.

Comments ( 1 )

Use Your Web Hosting SSH Session as A Tunnel for Socks5 Proxy Server to Circumvent Firewalls

As SSH is inherently tunnel-enabled for setting up socks5 proxy servers, you can instantly turn your personal computer into a socks5 proxy server by the help of PuTTY through your web hosting server, breaking through firewalls. The idea is to direct all traffic from your local computer browser through PuTTY SSH session to the web hosting server and back from it.

Here we go:

  1. First, make sure your web hosting provider provides SSH access to your hosting server. DreamHost (use coupon CASH60 for $60 discount) as well as a lot of other hosting companies do.
  2. Second, download PuTTY, run it, and set up the SSH account by entering your hosting server address in Host Name (or IP address).
  3. Add SSH tunnels by:
    Connection -> SSH -> Tunnels ->  give it a random Source port (in this example, ‘8844’), enter Desctination as ‘localhost’ and select Dynamic and Auto, and click Add. Now there should be an item of ‘D8844’ in the Forwarded ports list.
    putty tunnels proxy to set up socks 5 proxy server through web hosting server
  4. You may want to switch back to Session to save the session for easy access so that a simple double click would trigger the connection based on all the configurations you have done so far.
  5. Double click the saved session and log into your SSH account. Now you are in your web hosting server.

Leave the SSH session open and your personal computer has now become a socks5 proxy server. Open your favorite browser, for example, FF3:

  1. Tools -> Options -> Advanced -> Network -> Settings -> Manual proxy configuration -> SOCKS Host: localhost, Port: 8844 -> OK
    firefox-browser-proxy-settings
  2. You are now set. Fire up a tab and surf through the socks5 proxy on your local computer.

Remember though, that all traffic you use by browsing the web pages and downloading whatever stuff by the local proxy goes through your web hosting server and will be counted on the hosting bills.

Exciting! Now you’ve got your very own proxy server (socks5 server is the most versatile among all types of proxy servers including HTTP proxy and FTP proxy) that’s local, stable and in your perfect control for getting around all kinds of firewalls. Screw all those obsolete online proxy server lists with unusable proxy servers!

Comments ( 6 )

Recommended Steps and Tips in Choosing a Web Host

Web hosting can be very lucrative considering the marginal cost of each additional customer and the big chance of locking them up – most clients are reluctant to switch if the current host is good enough.

As a buyer, you want your money worth the deal. Here is a general list of things you should do at choosing a web hosting provider:

  1. Is their sales site design good and unique?
    Not necessarily has to be beautiful and gorgeous but uniqueness and aesthetics integrity should account for the seriousness they take in their business. A bad design or a copied design would just hint their inability to start decently, let alone their competence in serving you well.
  2. Is their sales site PageRank high enough? Does it have good amount of back links? Is it old enough?
    Senior sites are undoubtedly more trustworthy. And a senior site often bears high pagerank (check any site’s pagerank here) and a fair amount of backlinks (check for number of backlinks of a site by link:site.com in Google). You can also check for the age of a web hosting site by querying its whois infomation.
  3. Do others / paying customers review for them or against them?
    There’s plenty of places where you can find reviews and ratings of hosting companies. One of the biggest unbiased community is Web Hosting Talk. Just go search the name of the provider for what others are saying about them.
    You can also search for ‘xxx hosting reviews’ in Google for ratings and reviews. But be warned that some of the reviewing sites are financially affiliated with the web hosting providers and therefore the reviews should be taken as rather biased ones.

There’s actually much more to consider when choosing a web hosting company. Remember that there’s no perfect hosting provider except what’s perfect for you and that there’s no web hosting without a single negative reviews. So instead of obsessively seeking the most reliable hosting service, comparing for the most cost-effective one would be a better idea.

Update: A good approach is to try to detect and find out what famous websites are using as host by tracing the IP address and where the domain is hosted.

Comments Off on Recommended Steps and Tips in Choosing a Web Host

How is the web hosting industry different in China?

How Internet marketing and web businesses work in mainland China is substantially different from how things are in the English speaking world. It’s no exception with the web hosting industry that comes in as a fundamental part of all Internet businesses.

As a result of the lack of necessary legal accountability (it can be hard, with bureaucracy and a population of 1.4 billion), web plagiarism is pervading and generally deemed acceptable if the copying website leaves the credits intact, even with materials that are published with full rights reserved.

Understandably, there comes the subsequent abundance of web page scrapers, programmed automatic harvesting demons and intruding robots running all over the web and stealing things from each other. The last thing any web hosting providers in China want to do, is to provide a lot of bandwidth or monthly transfer to website owners. Currently as the most expensive resource, it’ll definitely be fully exploited and used up, causing substantial trouble to hosting providers and data centers.

Therefore, the major difference between web hosting in China and that in western countries is that the monthly transfer or bandwidth quota and server disk storage are incredibly much much smaller.

For instance, a $8 / month shared plan would now offer like dozens of TBs of monthly transfer and several TB storage from major cheap hosting providers. Some are even hyping with unlimited resources for the entry level shared plans costing no more than $15. However in China, with $8 / month which is roughly 650 RMB Yuan per year will only secure a monthly transfer of a few GBs or less and a disk storage of merely hundreds of MBs. That’s thousands times less competitive gauging from the same price level.

A hosting company so stingy in offerings will simply vanish in the western web hosting market, but in China, it just has to be this way.

Comments ( 5 )