Friday, August 26, 2011

skel directory

/etc/skel directory to push configuration to user

By default all files from /etc/skel are copied to the new user's home directory; when a new user account created. There are few files included in /etc/skel/ by default. you can copy custom script or whatever you want for every new user, just copied inside /etc/skel/

  • /etc/skel/.bash_logout
  • /etc/skel/.bashrc
  • /etc/skel/.profile
  • /etc/skel/.cshrc
  • /etc/skel/.exrc (/etc/skel/.vimrc)

Friday, August 12, 2011

How to open port on Linux

Open port 8080
Open flle /etc/sysconfig/iptables:
# vi /etc/sysconfig/iptables


Append rule as follows:
#iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

Save and close the file. Restart iptables:
# /etc/init.d/iptables restart
Open port 8080 that port is open Run following command:

netstat -tulpn | less
Make sure iptables is allowing port 8080
iptables -L -n

Refer to iptables man page for more information about iptables usage and syntax:
man iptables
Since you should not give up your firewall, you will have to add a rule to open this port.

Do:
cd /etc/sysconfig
cp iptables iptables.save_it
vi iptables

You will find lines like this:

Enter a line right behind this to open port 8080:

#iptables -A INPUT -p tcp -m tcp --dport 8080 --syn -j ACCEPT

Save it and restart the service "iptables" as described above and your port 8080 will work.


https://help.ubuntu.com/community/IptablesHowTo

Thursday, August 4, 2011

Linux User Disk quota implementation

What is disk quota?
Ans :
Disk quota is nothing but restricting the disk-space usage to the users. We have to remember one thing when we are dealing with disk quota i.e Disk Quota can be applied only on disks/partitions not on files and folders.

So how we can implement disk quota?
Disk quota can be implemented in two ways

a. On INODE
b.
On
BLOCK

What is an INODE?
Ans :
In Linux every object is consider as file, every file will be having an inode number associated and this is very much easy for computer to recognise where the file is located.

Inode stands for Index Node, and is the focus of all file activities in the UNIX file-system.
Each file has one inode that defines the file’s type (regular, directory, device etc),The location on disk, The size of the file, Access permissions, Access times.

Note that the file’s name is not stored in the inode.

So how to know what is your file Inode number?

Ans : Its just simple execute ls -i on your file.

ls -i xmls.txt

13662 xmls.txt

I think now you got what is INODE? Lets move on to BLOCK.

A block usually represents one least size on a disk, usually one block equal to 1kb. Some terms in Disk quota.

Soft limit : This is the disk limit where the user gets just a warning message saying that your disk quota is going to expire. This is just a warning, no restriction on data creation will occur at this point.

Hard limit : This is the disk limit where user gets error message, I repeat user gets error message stating that unable to create data.

Implementing QUOTA :
Step1 : Select/prepare the partition for quota, most of the time disk quota is implemented for restricting users not to create unwanted data on servers, so we will implement disk quota on /home mount point.

#vi /etc/fstab

Edit the /home mount point as follows
Before editing

/dev/hda2 /home ext3 defaults 0 0


after editing

/dev/hda2 /home ext3 defaults,usrquota 0 0


Step2 : Remounting the partition(this is done because the mount table should be updated to kernel). Other wise you can reboot the system too for updating of mount table, which is not preferred for live servers.

#mount -o remount,rw /home

Here -o specifies options, with remounting /home partition with read and write options.

Step3 : Creating quota database

#quotacheck -cu /home

The option -c for creating disk quota DB and u for user
Check for user database is created or not when you give ls /home you have to see auota.user file in /home directory,which contains user database.

Step4 : Switching on quota

#quotaon /home

Now get the report for default quota values for user surendra

#repquoata -a | grep surendra
surendra_anne --   4 0 0 1 0 0
surendra_a -- 4 0 0 1 0 0
surendra_test -- 16 0 0 4 0 0

Step5 : Now implementing disk quota for user phani on /home mount point(/dev/hda2)

#setquota -u surendra_anne 100 110 0 0 /dev/hda2

Step6 : Checking quota is implemented or not login to user surendra_anne and execute this command

#repquota -a 

or

#quota 

Step7 : Keep creating data, once 100MB is reached user will get an warning message saying, and when he reaches 110MB he can not create any more data.

Hint : To create a data file you can use seq command as below

#seq 1 10000 > test.txt

this command will create a file with 10000 lines with numbers in it.

Removing quota :
To do this one, all the users should log out from the system so better do it in runlevel one.

Step8 : Stop the disk quota

#quotaoff /home

Step9 : Removing quota database which is located /home

#rm /home/aquota.user

Step10 : Edit fstab file and remove usrdata from /home line

#vi /etc/fstab

Before editing

/dev/hda2 /home ext3 defaults,usrquota 0 0

After editing

/dev/hda2 /home ext3 defaults 0 0

Step11 : Remount the /home partition

#mount -o remount,rw /home
That’s it you are done with Disk Quota Implementation in Linux. Now test your self in creating Linux user disk quota on your own.