Friday, 28 January 2011

Install virtualenv and django, no-nonesense way

Install virtualenv

Installing virtualenv is easy on a Linux or Mac system, but the instructions that follow are Linux (Ubuntu, actually) specific. First you’ll need setuptools:

sudo apt-get install python-setuptools

Then we can easy_install virtualenv:
sudo easy_install virtualenv
We need to use sudo here because it has to install to a global location. Don’t worry, this is the last time we’ll need to do something as root.

Create your virtualenv

cd to wherever it is you keep your projects (for me, in ~/src), and run:
virtualenv --no-site-packages venv
In this instance I’ve chosen venv as the name for my virtual environment. The —no-site-packages command tells virtualenv not to symlink the global site packages into my local environment, just take the Python standard library. This is important, because it helps us avoid the dependency difficulties mentioned above.
At this stage you might want to add venv to your list of ignored files, as you don’t want it to be committed to source control:
echo "venv" >> .gitignore

Installing Django

Now, the trick with virtualenv is that it creates its own Python and easy_install binaries, which means you can install/run things specifically in your environment. Let’s install Django:
./venv/bin/easy_install django
And it’s done. easy. You might also want to install the MySQL bindings and IPython for ease of use:
./venv/bin/easy_install ipython python-mysql
To start a new Django project, you’ll note that a django-admin.py file will have been installed for you in the environment:
./venv/bin/django-admin.py startproject myapp
Obviously you can skip this step if you have an existing Django project.

Running Django

Now the last step, which is probably obvious by now, is to run Django’s runserver with the virtual Python binary:
cd myapp
../venv/bin/python manage.py runserver 0.0.0.0:8000
And you’re away!


Source: Bradley Wright


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