Sep 05

To check the version date of your OS (Linux distros):

uname -v

To find out the release:

uname -r

To display and show the complete kernel signature of your hosting server:

uname -a

Something like this will output similar information concerning your Linux kernel:

cat /proc/version

If you haven’t had the uname utility installed, you can get the kernel release version by:

cat /proc/sys/kernel/osrelease

You may also be interested in some other useful things to see within /proc.

Aug 21

How many user accounts are there on your hosting server? You can look up the number of server user accounts by the following command via SSH:

wc -l /etc/passwd

And it may output something like this:

76 /etc/passwd

Which means there are a total of 76 active users in the system. However, the actual number of human users of the server should be lower than the amount because there are system users created to carry out certain tasks.

Multiply the amount by 5 and you may get a rough number of websites hosted on your server.

Aug 02

wget command should be available in most hosting companies who offer SSH access to your hosting account. It is usually used to download stuff from the remote server, for example, to download something:

wget http://www.google.com/money.zip

However, there’s yet another hidden trick of wget that could enable you to make a mirror backup of any website – well, not actually any website but wget feels more comfortable with certain sites. WordPress blogs are perfect candidates for wget to mirror. Mirroring a WordPress blog can be done by a very simple switch of the wget command through SSH:

wget -mk http://www.example.com

All the documents relationships and HTML links will be taken care of so that local browsing of the mirrored copy will be completely no problem.

Jun 21

The default php configuration comes with a hard cap of 2MB on the size of uploaded file determined by the php.ini directive upload_max_filesize in conjunction with post_max_size. The maximum uploading size of a file is the lower. Therefore, to increase the uploading cap and raise uploading limit, you will need to edit those 2 directives in php.ini.

The location of php.ini varies distribution by distribution, in this example, with Ubuntu 9.04 Jaunty, php.ini is located at /etc/php5/apache2/php.ini, so

sudo vi /etc/php5/apache2/php.ini

Press / to find upload_max_filesize and change it to, say 8M:

upload_max_filesize = 8M

Press ESC, :, wq and Enter. Now the php.ini is saved with the new uploading file limit. Reload apache2 to read the new configurations:

sudo /etc/init.d/apache2 reload

Now you should be able to upload any file up to 8MB in size, in case you need larger uploading limit, in addition to change upload_max_filesize to, say, 16M, you must also edit post_max_size to more than or equaling to 16M because file uploads are processed through HTTP POST method.

May 30

FTP is an indispensable feature of servers that host and serve websites as it enables us to easily upload stuff to the remote server. On a Ubuntu server, with a little help of aptitude command (the package management program descended from Debian), you can install the most simple yet most common FTP daemon program for your server: vsFTPd.

apt-get install vsftpd

It is started automatically after successful installation. Stop it:

/etc/init.d/vsftpd stop

So that you can customize the configuration file:

vi /etc/vsftpd.conf

And make it look like:

pasv_enable=YES
pasv_max_port=8010
pasv_min_port=8001

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022

idle_session_timeout=3600

chroot_local_user=YES

pam_service_name=ftp

Restart the FTP service:

/etc/init.d/vsftpd start

Now you can try connecting to the FTP and transferring some stuff.

May 30

The default colors for comments (texts in /* */ or following // or #, …) in vi code highlighting are a little too dark. Ever wanted to make it more recognizable in SSH console?

Find and edit /etc/vim/vimrc with vi:

vi /etc/vim/vimrc

And add in this line:

colorscheme desert

Wherein desert is one of the available color schemes vim comes with. Now we will need to edit the actual color scheme file and change the highlighting colors:

/usr/share/vim/vimcurrent/colors/desert.vim

Change:

hi Comment ctermfg=darkcyan

To:

hi Comment ctermfg=blue

Save the change and exit. Run:

source /etc/vim/vimrc

And the changes will now take effect.

The default directory color of ls –color is also too dark, you can learn how to change the default directory color of ls –color.

May 30

After you have enabled the color switch of ls command in shell console, it’s nice but some may complain that the deep blue color of the directories are too dark to recognize sometimes. Let’s change that.

Just open up the .profile or .bash_profile file under your home directory and put this line in it:

export LS_COLORS='di=01;34'

Done! Now the color of the ls directory listings is much lighter and easier to recognize. There’s also a tip of how to change the default dark color for comments in vi text editor.

May 30

Add the following snippet in the .profile or .bash_profile under your home directory:

export PS1='[\[\e[1;31m\]\u\[\e[0m\] - \[\e[32m\]\w\[\e[0m\]]$ '
export LS_COLORS='di=01;34'
alias ls='ls --color -l'

If you are ‘supergirl’, your Linux home directory would be located at: /home/supergirl, and the file you should add the above lines to is: /home/supergirl/.profile or /home/supergirl/.bash_profile.

What is LS_COLORS doing here?

May 30

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

May 30

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.

May 30

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.

May 30

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.

Apr 13

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?!)

Apr 13

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%.

Apr 13

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.