Friday 31 December 2010

Disable Root SSH Login on Debian

Before we begin, you should make sure that you have a regular user account and that you can su or sudo to root from it. So  do these first:


adduser usrer1
assign a passwd to user1. and then add it to sudoers. But first need to install sudo:


apt-get install sudo
add this line inside to 


        nano /etc/sudoers


user1  ALL=(ALL) ALL


Open the file up while logged on as root.
nano /etc/ssh/sshd_config
Find this section in the file, containing the line with “PermitRootLogin” in it.
#LoginGraceTime 2m
#PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
Make the line look like this to disable logging in through ssh as root.

PermitRootLogin no
Now you’ll need to restart the sshd service:

/etc/init.d/ssh restart
Now nobody can brute force your root login, at least.

Source: How-to Geek

Monday 27 December 2010

install the latest nginx

You can get the latest stable version of Nginx from the Nginx PPA on Launchpad:
You will need to have root privileges to perform the following commands.
 
sudo su -
echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
apt-get update 
apt-get install nginx

Source: nginx wiki

Upgrade Ubuntu server

aptitude update
and install the package update-manager-core:
aptitude install update-manager-core


Then run

do-release-upgrade

More details in howtoforge

Friday 24 December 2010

'add-apt-repository: command not found'

add-apt-repository isn't installed by default. You have to install the python-software-properties package first.

sudo apt-get install python-software-properties

Thursday 9 December 2010

Install Postgresql 8.4 on Ubuntu 10.10

Install postgres and the python libraries:
sudo apt-get install postgresql-8.4 postgresql-client-8.4 python-psycopg2
Modify the config file to allow local connections:
sudo nano /etc/postgresql/8.4/main/pg_hba.conf
Add the line:
local     all         all     md5
Save the changes to the file and restart the server.
sudo /etc/init.d/postgresql restart
Set the password for the postgres user:
sudo passwd postgres
Change to the postgres user:
su - postgres
Create a new Database:
createdb mydb
Login to the postgres shell and point to our new database:
psql mydb
Now from the postgress shell create a user and give him access to the database:
mydb=> CREATE USER myuser WITH PASSWORD 'myPassword';
mydb=> GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
mydb=\q
Done!

Source:  Videntity's Blog


Sunday 5 December 2010

batch rename in Linux command line

The most intuitive way is  'sed' a loop. like this


for file in *.*; do mv $file `echo $file | sed 's/foo/bar/g'` ; done;
-----





Friday 3 December 2010

DDoS blocker script

First off, try this handy command to check connected IPs:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n


(D)DoS Deflate is a lightweight bash shell script designed to assist in the process of blocking a denial of service attack. With (D)DoS Deflate you can configure how long will the IP address will be blocked and how many connection considered as DDoS.

How to install it:
1. Open your terminal and login as root
2. Download (D)DoS Deflate:

wget http://www.inetbase.com/scripts/ddos/install.sh

3. Give execute permission to the script:

chmod 0700 install.sh

4. Install it:

./install.sh

To add your ip address as whitelist, edit this file:

nano /usr/local/ddos/ignore.ip.list

Configure (D)DoS Deflate:

nano /usr/local/ddos/ddos.conf

More details at (D)Dos Deflate


-------------------REMOVING IPTABLES RULES-------------------
With command line :

iptables -L INPUT -n --line-numbers

You'll get the list of all blocked IP. Look at the number on the left, then :

iptables -D INPUT ((line number here))

Unix command to analize access.log

The first column is number of connection attempts.

cat access.log | awk '{print $1}' | sort | uniq -c | sort -n

Tuesday 16 November 2010

How to backup/restore site and mysql database

Frequently you would need to back up and restore site's files and database

-To backup drupal files, better to compress them first so go to the root:

tar -cvjf site.tar.bz2 /path/to/site

- To decompress the above:

tar -xjvf site.tar.bz2

- To backup mysql database ('username' is Mysql username)

mysqldump -u username -p databasename > /path/to/dumpfile.sql

- Also it is better to compress the database if you need to download it:
tar -xjvf dumpfile.sql.tar.bz2 /path/to/dumpfile.sql

- To restore a backed up mysql databas (after decompressing it)

mysql -u username -p databasename < /path/to/dumpfile.sql

Monday 25 October 2010

Set up virtualenv and start a django project

This has been a headacke for me. At last I figured out that the best practice is to set up projcets through a virtualenv. So let's first install it

easy_install virtualenv


Afterwards, you must decide where you want to store your virtual environments, Then, we will create our actual new virtual environment.

mkdir ~/djenv
virtualenv ~/djenv/env1

Then you need to activate the environment:

source ~/djenv/env1/bin/activate

You should see '(env1)' comes at the left of the terminal.

So now you can install Django in this environment:

pip install Django


Set up django project wherever you like, e.g.:

mkdir -p ~/sites
cd ~/sites
django-admin.py startproject proj1


To get out of the environment:

deactivate env1


That's it. enjoy!

For mor info...

Friday 22 October 2010

Split video file using ffmpeg and mencoder

Example:

ffmpeg -i input.flv -ss hh:mm:ss -t hh:mm:ss output.flv

Where:

-ss :  Buration
-t : Start time
hh: hours
mm: minutes
ss: seconds

If this does not work try mencoder:

 mencoder -ss 00:00:00 -endpos 00:35:20 -oac pcm  -ovc copy input.mp4 -o output.mp4

Wednesday 20 October 2010

script to set drupal permissions

#! /bin/bash
cd /var/www/drupal
chown -R drupmin:www-data .
find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;

cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chm$
find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmo$


echo "Permission rebuildng is done!"

Saturday 16 October 2010

Compress/Decompress commands: Zip, TAR, TAR.GZ, TAR.BZ2

ZIP

To compress a directory with zip do the following:

# zip -r archive_name.zip directory_to_compress

Here’s how you extract a zip archive:

# unzip archive_name.zip

TAR

# tar -cvf archive_name.tar directory_to_compress

And to extract the archive:

# tar -xvf archive_name.tar.gz

This will extract the files in the archive_name.tar archive in the current directory. Like with the tar format you can optionally extract the files to a different directory:

# tar -xvf archive_name.tar -C /tmp/extract_here/

TAR.GZ

This format is my weapon of choice for most compression. It gives very good compression while not utilizing too much of the CPU while it is compressing the data. To compress a directory use the following syntax:

# tar -zcvf archive_name.tar.gz directory_to_compress

To decompress an archive use the following syntax:

# tar -zxvf archive_name.tar.gz

This will extract the files in the archive_name.tar.gz archive in the current directory. Like with the tar format you can optionally extract the files to a different directory:

# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/


TAR.BZ2

This format has the best level of compression among all of the formats I’ve mentioned here. But this comes at a cost – in time and in CPU. Here’s how you compress a directory using tar.bz2:

# tar -jcvf archive_name.tar.bz2 directory_to_compress

This will extract the files in the archive_name.tar.bz2 archive in the current directory. To extract the files to a different directory use:

# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

source

create or delete mysql databases

- To backup mysql database
mysqldump -u username -p databasename > /path/to/dbfile.sql
- To restore a backed up mysql databas

mysql -u username -p databasename < /path/to/dbfile.sql

Convert avi files to mp4 using ffmpeg

ffmpeg -i input.avi -f mp4 -strict experimental -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 output.mp4





--