Disable user login to SSH
In this tutorial, you will learn how to disable user logins via SSH. By default on newer Ubuntu systems and some other Linuxes with SSH installed, all users who have an account on the system are permitted to login via SSH. This is undesirable in certain situations.
Use htaccess to Block IP Address
In this tutorial we will show how to use an .htaccess file to block an IP address. This is one of several methods of blocking incoming requests to a web server. Other methods include blocking the IP address at the firewall or in PHP code, etc.
There are many reasons why you would want to block an IP address. It may be someone or something wasting or stealing your resources by making multiple requests to files on your server. It could be someone trying to spam your site. Whatever the reason for wanting to block an IP address, the htaccess file comes to the rescue.
Backup Website and Email Encrypted Backup using a shell script on Ubuntu/Linux
In this tutorial, we will show you how to backup a website and then encrypt the backup before emailing it using only a shell script. This guide is for those who are running their web server on Ubuntu or another version of Linux. This is very useful as a website can be backed up automatically using cron, encrypted for protection, and emailed to a safe place.
Bash For Loop
The Bash for loop is useful when we want to repeat some instructions a specified amount of times. Loops are considered iterative commands as they perform iterations, also known as repetitions.
For example, if we want to run a particular command 5 times, we would specify the command inside of a for loop and then tell the loop to run 5 times.
The following tutorial explains.
Get Bash Version
If you are wondering what version of Bash am I using, then you have come to the right place. There are a number of reasons why one would want to know their Bash version. The most likely reason is compatibility. Even though the commands remain the same for the most part, different versions of Bash may add different features and functionality that may not be available in older versions.
Substring in Bash
To find a substring in Bash, we use the bash substring operation, one of the many string manipulation operations that the Bash shell offers.
This substring operation is similar in syntax to the PHP Substring operation for those of us who do PHP programming.
Retrieving a substring in Bash is fairly easy as we will see in the tutorial below.
The syntax for the Bash substring function the way we will use it is as follows:
STRING:start:length
Change hostname on Ubuntu
The hostname of an Ubuntu system is usually specified when it is being installed. Especially if you were not the one who installed the system, you may want to change the hostname to something that is more meaningful to you. The importance of the hostname on an Ubuntu system is usually overlooked as it is not seen as something worth changing. The truth is, if you have a properly set hostname, you will be easily able to determine the exact server that you currently have a terminal open on.
The tutorial below shows how to change the hostname on Ubuntu.
Concatenate strings in Bash
To concatenate strings in Bash, we use special characters to delineate the variable from the literal string.
String concatenation is useful for joining the values of variables to a string before outputting it or using it to perform some other function.
The Bash concatenate tutorial below shows how this not so well known technique works.
If we wanted to concatenate a variable to a string in a Bash script, we would do it as shown below:
#!/bin/bash LOVE="Tutorial Arena" OUTPUT="I love ${LOVE} so much!"
Run shell script from PHP
Running a shell script or command from PHP offers a number of conveniences to an administrator. When properly set up, shell scripts and commands can be run by simply requesting a web page over the Internet. The web server would receive the request and then pass it on to the PHP interpreter. By using special PHP functions, we are then able to make PHP run the shell script or command for us.
Check open ports on Ubuntu Linux
One may want to check open ports on Ubuntu to ensure that there are no services listening that shouldn't be. If we remember, a port is what an application will use to communicate with another application, provide a service, etc. To get an idea of what services are running on a system, we would need to check the open ports on the system.
Use cron to run PHP script
Using a cron job to run a PHP script is very easy if you know how. If we recall, cron is a Unix/Linux utility that is used to perform tasks at specified intervals. By setting up a cron job with the appropriate parameters, we can get our system to execute PHP scripts or any other kind of script.
Create file with dd on Linux
Occasionally, for testing purposes, we will want to create a large file. There is a handy utility installed on most Linux systems called dd which makes the task of creating files of any size very easy.
The beauty of dd is that it works very fast and very large files can be created quite quickly.
The tutorial below will show how to create a file of any size with dd on Linux.
Apache compiled in modules
Apache is a very well-designed and modular web server. Its power and convenience partly comes from its ability to use various modules, and the ease in which these modules can be changed as necessary. Specific modules can be compiled into the server when it is being built so that a web server suited for a particular task is ready out of the box.
Most times, we are not the ones who have compiled Apache so we have no way to immediately know what modules have been compiled into it. Coming to our rescue is a simple command we can execute to determine Apache's compiled modules.
Check Apache version on Ubuntu linux
To ensure that we have the latest version of the Apache web server running, we need to perform a check on our current version.
In the tutorial below, we will demonstrate how easy it is to check our Apache version on Ubuntu or other similar modern flavour of Linux.
To check what version of Apache we have running, we can open a terminal and execute the following command:
apache2 -v
Send Email with attachment from the command line in Ubuntu Linux
Sending emails with attachments from the command line in Ubuntu is easily accomplished using a tool called mutt. Mutt allows us to send emails non-interactively. That is, we can invoke mutt from a shell script and it will perform the specified tasks for us with no further intervention needed on our part.
We can also run mutt from a shell (such as bash) or even as a cron job and have it carry out our desired tasks.
Bash Timestamp - Get Unix timestamp in bash
The Unix timestamp is a numeric representation (usually a very large number) of a particular date and time.
The current timestamp on a system may come in handy when it comes to recording/checking the last modification date of files or other such time-sensitive events.
We can get the timestamp from our system using the command line. To get the current Unix timestamp from a bash terminal, we can execute the following command:
date +%s
Bash Sleep Command - Pause the execution of a bash script
The bash shell provides an easy way for us to pause the execution of a shell script through the sleep command.
The sleep command takes a number as its parameter and then pauses the execution of the shell script for that number of seconds.
This tutorial has bash sleep examples to get you up to speed with using the bash sleep command.
Exclude files from Tar Archive
Tar is a UNIX/Linux utility which is used to compress files for storage in an archive. When we tell tar to compress and create an archive of a directory, it will go ahead and include all the files in that directory.
Sometimes we may want to exclude a particular file from an archive. Tar allows use a convenient option to specify a file or files to exclude when making the archive. The tutorial below shows how we do a tar exclude file operation by using the command line.
Check Ubuntu version from the Command Line
In this tutorial, you will learn how to check your Ubuntu version from the command line. To get the version of Ubuntu or the kernel that is running is quite a simple task when using the terminal. Especially on an Ubuntu server where you may only interact with the system through a terminal, it may be easy to lose track of which version of the operating system is running. The version of the kernel which is running may also be obscure since you rarely need that sort of information.
Remove 'Preview' button in Drupal 6 comment form
By default in Drupal 6, there is a 'Preview' button in addition to a 'Save' button in the form which allows a user to post a comment.
For those of us who think it is silly to have a preview before posting, the good news is that you can remove the button quite simply with a bit of code.
Place the following code in the template.php file which exists in the directory for the theme that you are using. If your theme does not use a template.php file, go ahead and create one.
This code goes in template.php:
<?php