Access Control Lists

December 30, 2010

Access controls were easier to manage in the past. With a few commands (e.g chown, chmod) we were manipulating file permissions. There were a few attributes to manage and security wasn’t much of a concern as we have now. As the security threats increase we have to add additional levels of protection. What I am telling you now is how you can change permissions of files in Linux with a different method.

In order to use POSIX access control lists, your kernel must have this feature enabled.  In order to understand you have this feature or not, you can have a look at into your kernel config file in the first place for the string “POSIX_ACL”. If you see a similar output in which the attributes are set to “y”, then you have the feature.

[root@rh54srv1 ~]# grep “POSIX_ACL” /boot/config-`uname -r`
CONFIG_EXT2_FS_POSIX_ACL=y
CONFIG_EXT3_FS_POSIX_ACL=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_FS_POSIX_ACL=y

If you are using a redhat based system, you should have it by default. Shortly if you file system has been mounted with the option “acl” then you can use POSIX ACLs. Here is a brief explanation of how you can use ACLs with examples.

1) I have a test folder which belongs to root user only but I want also the user “accountant” to have read,write and execute permissions on this folder by keeping the current permission.

[root@rh54srv1 /]# ls -l / | grep test
drwx——
2 root   root    4096 Dec 31 00:11 test

2) First run setfacl command as follows;

#setfacl -R -n -m u:accountant:rwx  /test

and check the permissions;

[root@rh54srv1 /]# ls -l / | grep test
drwx——+ 2 root   root    4096 Dec 31 00:11 test

Have you seen the difference? A plus sign has been added into the flags. Now lets display the new permissions with getfacl tool.

[root@rh54srv1 /]# getfacl /test
getfacl: Removing leading ‘/’ from absolute path names
# file: test
# owner: root
# group: root
user::rwx
user:accountant:rwx #effective:—
group::—
mask::—
other::—

GRE tünel nasıl oluşturulur

June 14, 2010

Bu yazıda bir örnekle Linux altında nasıl GRE tünel oluşturacağımızı anlatmaya çalışacağım.

Birbirine Internet üzerinden erişebilen iki Linux cihaz düşünelim. (IP adresleri yine de Internet üzerinde kullanılmayan bloktan verilmiştir)

IP TANIMLARI

node1 (eth0 internet, eth1 iç ağa bakan kısım olsun)
eth0 : 192.168.200.150/24
eth1:  10.1.1.1/24
tunel arayuzu (tonode2): 172.16.151.1/30

node2 (eth0 internet, eth1 iç ağa bakan kısım olsun)
eth0:  10.10.10.150/24
eth1:  10.2.1.1/24
tunnel arayuzu (tonode1): 172.16.151.2/30

node1 ve node2 cihazlarının birbirlerine eth0 arayüzleri üzerinde Interneti kullanarak erişebildiğini düşünelim. Sırasıyla cihazları yapılandıralım.

Continue Reading »

SSH timeout

May 4, 2010

If you have a problem of frequent disconnection from your SSH server, you can enable the following setting in your sshd_config file and restart SSHD.

ClientAliveInterval 60

The exact description of what this does is

ClientAliveInterval
Sets a timeout interval in seconds after which if no data has
been received from the client, sshd will send a message through
the encrypted channel to request a response from the client.
The default is 0, indicating that these messages will not be
sent to the client.  This option applies to protocol version 2
only.

SPBCHSW81

SPBCHSW82

SPBCHSW91

SPBCHSW92

vncserver configuration in redhat

January 19, 2010

VNC server configuration is pretty straight forward in redhat. Here are the steps that you should complete in order to run a functional VNC server in a few minutes.

Our test user is : mert

1) Adjust /etc/sysconfig/vncservers config file as below:

VNCSERVERS=”2:mert”

2) Login to mert account and set vncpassword

[root@rh54-3 sysconfig]# su – mert
[mert@rh54-3 ~]$ vncpasswd
Password:
Verify:
[mert@rh54-3 ~]$

3) Start vnc service and add it into the startup.

[root@rh54-3 sysconfig]# /etc/init.d/vncserver start
Starting VNC server: 2:mert xauth:  creating new authority file /home/mert/.Xauthority

New ‘rh54-3.penguen.com:2 (mert)’ desktop is rh54-3.penguen.com:2

Creating default startup script /home/mert/.vnc/xstartup
Starting applications specified in /home/mert/.vnc/xstartup
Log file is /home/mert/.vnc/rh54-3.penguen.com:2.log

[  OK  ]

[root@rh54-3 .vnc]# chkconfig vncserver on

However if you connect via VNC client now, you won’t see default GNOME but twm instead.

Open the file /home/mert/.vnc/xstartup and uncomment the following lines (remove the hash in front)

#unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc

Restart VNC server to have the new changes affected.

[root@rh54-3 .vnc]# /etc/init.d/vncserver restart
Shutting down VNC server: 2:mert                           [  OK  ]
Starting VNC server: 2:mert
New ‘rh54-3.penguen.com:2 (mert)’ desktop is rh54-3.penguen.com:2

Starting applications specified in /home/mert/.vnc/xstartup
Log file is /home/mert/.vnc/rh54-3.penguen.com:2.log

[  OK  ]


4) Below is a step by step login into VNC server from my windows OS

a) connection screen

b) Password screen

c) GNOME screen

Screen command

January 19, 2010

I hadn’t used screen much in the past but I see that it is a very handy tool. I just would like to add some tips about screen command.

Ctrl-a c : creates a new screen shell
Ctrl-a TAB: switches focues between upper and lower split terminal
Ctrl-a “ : Display a list of managed windows. (This is the most I like:)

It is very useful to use the option “-t” in screen as it allows you to mark your instances. If you run a new screen sheel with the command;

screen -t /var/log/local6 1 tail -f /var/log/local6

Then when you run Ctrl-a “ to list the windows, you will recognize your tailing window with the title “/var/log/local6″

This is a very short article about screen. I hope on the way I use this tool, I may improve this it.

Interface bonding

January 19, 2010

As network cards or links may fail, we may solve this problem by creating multiple links to our network devices. One way is interface bonding which we will configure one in our example.  I assume that your linux have three interfaces eth0,eth1 and eth2. We will use two of the interfaces;

Slave Interfaces : eth1 and eth2
Bonding interface: bond0

1) First add the followings into /etc/modprobe.conf file to provide module paramaters:

alias bond0 bonding
options bond0 mode=active-backup  miimon=100

With this configuration, we use active backup mode. By that, if the primary interface goes down for some reason, bonding system will fail over into the other interface. If you want to use round robin load balancing which will enable to use both interfaces actively use “balanced_rr” instead of “active-backup

2) Configure slave and bonding interfaces.


/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:47:49:8d
MASTER=bond0
SLAVE=yes

/etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth2
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:47:49:97
MASTER=bond0
SLAVE=yes

/etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.0.0.230
NETMASK=255.255.255.0
BROADCAST=10.0.0.255

3) Now bring up the bonding interface and look at “ip addr” output

#ifup bond0

#ip addr

3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
link/ether 00:0c:29:47:49:8d brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
link/ether 00:0c:29:47:49:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.10.129/24 brd 10.0.10.255 scope global eth3
9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue
link/ether 00:0c:29:47:49:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.230/24 brd 10.0.0.255 scope global bond0

You might have noticed that both eth1 and eth2 use the same MAC address which actually what we expect and how it works.

In order to see the bonding status and current active slave interface, issue the following;

[root@rh54]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth1
MII Status: down
Link Failure Count: 1
Permanent HW addr: 00:0c:29:47:49:8d

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:47:49:97

Here you can see the real mac addresseses of the interfaces.

4) Fail over test

You can actually test how fail over works. In my vmware test system, I have disconnected eth1 and active slave (eth1)  failed over into eth2 at around 3 secs. (I was pinging at the same time) It switches over quite fast but what I have realized is, system keeps the previous mac address even though the interface having that MAC failed. For example in my setup (according to the previous bond0 output), eth1 is failed and eth2 is active slave however other nodes in the network know my 10.0.0.230 IP of having 00:0c:29:47:49:8d MAC. It is quite reasonable indeed. We don’t have to change mac and send unnecessary gratitous arp requests. Once one of your interfaces goes down in your bonding you will see a similar output in your dmesg.

eth1: link down
bonding: bond0: link status definitely down for interface eth1, disabling it
bonding: bond0: making interface eth2 the new active one.

That is all for this article, please drop your comments if you have anything to add or questions.

You can find quite a lot of information about bonding at the following address. I recommend you to read it

http://www.linuxfoundation.org/collaborate/workgroups/networking/bonding

sysconfig.txt

January 9, 2010

You can find quite a lot of files in /etc/sysconfig however in configuring them you may have trouble but there is a file that you can use to understand what attributes you can use for each file. It is sysconfig.txt. In my current Redhat 5.4 system the file is at the following location as it comes with the package initscripts.

/usr/share/doc/initscripts-8.45.30/sysconfig.txt

For example if you want to set ethernet options into your ifcfg-eth0 file below is the quote from this file;

ETHTOOL_OPTS=…
Any device-specific options supported by ethtool. For example,
if you wanted to force 100Mb full duplex:
ETHTOOL_OPTS=”speed 100 duplex full autoneg off”
Note that changing speed or duplex settings almost always
requires disabling autonegotiation with ‘autoneg off’.

Installing RPM file into a different root

January 9, 2010

One day you may have to install an RPM file into a different root folder. For example under rescue mode though you can chroot as an option. Here is the handy option for you to do it.

#rpm -ivh zip-2.31-2.el5.i386.rpm –root /mnt/sysimage

MBR recovery and grub reinstall

January 9, 2010

In the event that partition table is corrupted or boot loader has gone, here are some steps that you can take in order to boot the system as normal.

I hope that you have taken the backup of partition table previously with the command;

#sfdisk -d /dev/sda > /root/sda_partition_table.out

Or if you also want to backup the whole MBR to a file do this;

#dd if=/dev/sda of=/tmp/mbr_sda.out bs=512 count=1

From now on, I assume that you have booted the system in rescue mode with networking support.

1) The first thing is to paste this partition table back into its original space. Presumably, you have copied the partition table from network and put it under /tmp/sda_partition_table.out

#sfdisk /dev/sda <  /tmp/sda_partition_table.out

This will fix your partition table. Now time to fix MBR

2) As the MBR has gone, we have to write MBR again. Do the followings;

#grub

grub> root (hd0,0)
grub>setup (hd0)
grub>quit

The root (hd0,0) command assumes that your boot partition is in /dev/sda1

After these commands, you should be able to boot your system as before.

How to use LVM in rescue mode

January 9, 2010

One day it may happen to you that either MBR is corrupted or partition table has gone then you will need rescue mode. However there is one problem,  what if you use LVM in your system. Because redhat does everything for us we don’t actually know what it does for initialization unless you have looked inside the init scripts.

In my rescue environment when I issue “lvm vgdisplay” , I was able to display the configuration but there was no device files under /dev. To overcome this problem do the followings:

#lvm vgscan
#lvm vgchange -ay

The first command “vgscan” scans all disks for volume groups and the second one “vgchange” makes the logical volumes known to the kernel. To deactivate you should but “n” instead of “y” on the command line.

Now you can access logical volumes.

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org