20 January 2014

UNIX Timestamps: mtime, ctime, and atime

Unix keeps 3 timestamps for each file: mtime, ctime, and atime.

Most people seem to understand atime (access time), it is when the file was last read.

There does seem to be some confusion between mtime and ctime though. ctime is the inode change time while mtime is the file modification time. "Change" and "modification" are pretty much synonymous. There is no clue to be had by pondering those words.
Instead you need to focus on what is being changed. mtime changes when you write to the file. It is the age of the data in the file. Whenever mtime changes, so does ctime. But ctime changes a few extra times. For example, it will change if you change the owner or the permissions on the file.


Let's look at a concrete example. We run a package called Samba that lets PC's access files. To change the Samba configuration, I just edit a file called smb.conf. (This changes mtime and ctime.) I don't need to take any other action to tell Samba that I changed that file. Every now and then Samba looks at the mtime on the file. If the mtime has changed, Samba rereads the file. Later that night our backup system runs. It uses ctime, which also changed so it backs up the file. But
let's say that a couple of days later I notice that the permissions on smb.conf are 666. That's not good..anyone can edit the file. So I do a "chmod 644 smb.conf". This changes only ctime. Samba will not reread the file. But later that night, our backup program notices that ctime has changes, so it backs up the file. That way, if we lose the system and need to reload our backups, we get the new improved permission setting.

Here is a second example. Let's say that you have a data file called employees.txt which is a list of employees. And you have a program to print it out. The program not only prints the data, but it obtains the mtime and prints that too. Now someone has requested an employee list from the end of the year 2013 and you found a backup tape that has that
file. Many restore programs will restore the mtime as well. When you run that program it will print an mtime from the end of the year 2013.

But the ctime is today. So again, our backup program will see the file as needing to be backed up.

Suppose your restore program did not restore the mtime. You don't want your program to print today's date. Well no problem. mtime is under your control. You can set it to what ever you want. So just do:

$ touch -t 201301231150.30 employees.txt

This will set mtime back to the date you want and it sets ctime to now. You have complete control over mtime, but the system stays in control of ctime. So mtime is a little bit like the date on a letter while ctime is like the postmark on the envelope.

02 December 2011

Exit the VM from OVM Console

Most of us are aware of this command

xm console {vm-name} to connect the VM from dom0

But once you have initiated, you wont be able to go back to dom0.These are the control commands that will help you to get back to dom0

ctrl + ]   "->" If you have initiated the command from the console
ctrl + 5  "->" If you have initiated the command via Putty Session

31 July 2010

Run level - Solaris

The first thing I noticed was /etc/inittab file is different from the Linux version. However, runlevel are quite identical

Default Solaris Run Level

• S : Single user state (useful for recovery)
• 0 : Access Sun Firmware ( ok> prompt)
• 1 : System administrator mode
• 2 : Multi-user w/o NFS
• 3 : Multi-user with NFS
• 4 : Unused
• 5 : Completely shutdown the host (like performing a power-off @ OBP) 
• 6 : Reboot but depend upon initdefault entry in /etc/inittab

Solaris 8/9 Find out runlevel

To find out current runlevel use who command:

$ who -r

Output:

. run-level 3 Mar 3 14:04 3 0 S

Solaris changing runlevels after bootup

You need to use init command, for example change runlevel to 2.

# /sbin/init 2

Solaris changing the default runlevel

An entry with initdefault (in /etc/inittab file) is scanned only when init is initially invoked. init uses this entry to determine which run level to enter initially.

Open /etc/inittab file:

# vi /etc/inittab
Find out this entry:
is:3:initdefault:

Change is:3 to number you want, don't use S, 0, 6 ;). Save file.



* Only init states 0, 1, 5, 6, and S can be reached using shutdown.

Make changes to .bash_profile and need to update the current session?

$ source .bash_profile


With the above command, the user does not have to logout.

How to skip a service while starting in HP-UX

During the HP-UX OS booting,if you want the service/daemon need to be skipped  press crtl + backslash.

Most of us tried pressing ctrl + c, that wont work during the booting

18 January 2010

Symbolic links

namei can be used to trace the endpoint of a cascaded symbolic link

Eg.,

$ namei /dev/cdrw
f: /dev/cdrw
 d /
 d dev
 l cdrw -> scd0
   b scd0
$

SELinux....

Most of the Linux admins especially working on RedHat used to disable this option during installation ofcourse includes me as well....But later i realised the feature it offers.

Today much attention has been paid to network security,data security and computing security using various products available in the market but none of us are realizing the local exploit(Malware/Malicious) is a big one than the rest of the things.

SELinux takes care of control this local exploit....in other words its a kind of access control mechanism.


Is that is the only reason we need this....or do we have a flaw in the existing access control system.

Inherent flaw in the traditional permissions model is DISCRETION.I.e.,Owner of a particular file can change the permissions at his own will which might result in security breach.

By contrast,SELinux implements Mandatory Access Control(MAC) where access control decisions are not at the discretion of individual users or even system administrators.

22 December 2009

HP-UX Boot process


HP-UX OS Boot Process - PA-RISC Machines

19 January 2009

Fault tolerance for NIC

More and more data centers are in the process of setting up unmaned data centers.Admins are trying their best to have a fault tolerance solution for each software and Hardware component.
Here is a fault tolerance soultion for a Network interface via bonding in Linux

1.Create a file ifcfg-bond under /etc/sysconfig/network-scripts where is the binding number.
2.cat ifcfg-bond0

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=192.168.41.0

NETMASK=255.255.255.0
IPADDR=192.168.41.250
USERCTL=no


3.Network interfaces to be bound together must be configured by adding MASTER= and SLAVE= directives to their configuration files.

4.Configuration files for the two interface files

DEVICE=eth<0/1>
BOOTPROTO=none

ONBOOT=yes
MASTER=bond0

SLAVE=yes
USERCTL=no

5.Configuring alias in modprobe.conf
alias bond0 bonding

options bond0 milmon=80 mode=1

modprobe to activate the aliases and restart the network service.

6. Now bond0 will be up.Output of ifconfig will show the same ip-address for bond0,eth0 & eth1.

27 August 2008

How to list the contents of the EFI directory on hp-ux IPF systems?

First find the default boot device using the setboot command
# setboot
Primary bootpath : 0/4/1/0.0.0.7.0
HA Alternate bootpath : 0/0/2/0
Alternate bootpath : 0/4/1/0.0.0.6.0
Autoboot is ON (enabled)#


Find the corresponding dirver for the Hardware path using ioscan
# ioscan -funC disk

disk 39 0/4/1/0.0.0.6.0 sdisk CLAIMED DEVICE HP DG146ABAB4
/dev/dsk/c17t6d0 /dev/dsk/c17t6d0s2 /dev/rdsk/c17t6d0 /dev/rdsk/c17t6d0s2
/dev/dsk/c17t6d0s1 /dev/dsk/c17t6d0s3 /dev/rdsk/c17t6d0s1 /dev/rdsk/c17t6d0s3
disk 40 0/4/1/0.0.0.7.0 sdisk CLAIMED DEVICE HP DG146ABAB4
/dev/dsk/c17t7d0 /dev/dsk/c17t7d0s2 /dev/rdsk/c17t7d0 /dev/rdsk/c17t7d0s2
/dev/dsk/c17t7d0s1 /dev/dsk/c17t7d0s3 /dev/rdsk/c17t7d0s1 /dev/rdsk/c17t7d0s3
#


List the contents of EFI shell.This can be useful to compare root and root mirror disks.

# lifls -l /dev/rdsk/c17t7d0s2
volume ISL10 data size 7984 directory size 8 06/10/27 14:23:07
filename type start size implement created
===============================================================
ISL -12800 584 242 0 06/10/27 14:23:07
AUTO -12289 832 1 0 06/10/27 14:23:07
HPUX -12928 840 1024 0 06/10/27 14:23:07
PAD -12290 1864 1468 0 06/10/27 14:23:07
LABEL BIN 3336 8 0 08/07/01 05:19:23#

22 August 2008

Sudoers file on Solaris 10

sudo is available from the SFWsudo package on Solaris 10.
To use it a /etc/sudoers file has been set but still leading to the following error

user NOT in sudoers

Hopefully, truss will help :-)

root@server:/# truss -o /tmp/output sudo ls

The /tmp/output file is answering the enigma:

root@server:/# grep sudoers /tmp/output
lstat("/opt/sfw/etc/sudoers", 0xFFBFFB28) = 0
open("/opt/sfw/etc/sudoers", O_RDONLY) = 4

The sudoers file to edit is in /opt/sfw/etc

01 July 2008

Raw devices & Block devices

Most of the people will get confused when to use /dev/dsk/c0t1d0s7 and /dev/rdsk/c0t1d0s7 device files.

Generally /dev/dsk is a block disk device whereas /dev/rdsk is a character disk device

As a thumb rule raw devices are used before filesystem creation.Block devices are user after filesystem creation.

E.g., In Solaris whenever you create a new slice using format command a raw physical slice or a Raw Device will be created which is addressed as /dev/rdsk/c#t#d#s#
After formatting it with newfs command the slice will be addressed as /dev/dsk/c#t#d#s# which can now be used for mounting.

newfs /dev/rdsk/c0t1d0s4
mkdir /oracle
mount /dev/dsk/c0t1d0s4 /oracle

After mounting /dev/dsk/c#t#d#s# is called as Block Device

29 May 2008

Soft limit & Hard limit

Most of us encountered to increase the limit of file descriptors while installing a high end 3pp(party product).In doing so we will encounter with two different kinds of limits i.e.soft vs hard.

Hard limits are a kernel-configurable item and users can't exceed them. Soft limits are the user defaults and users can change that using the ulimit command.

Basically, soft limits can be changed to anything up to the hard limit. Soft limits are warning barrier. When a user reaches the soft limit they will get an warning message but are still allowed to use more space up to the hard limit.

Since its a kernel tunable we have to define the value in /etc/system and /etc/sysctl.conf for Pre-Solaris 10 and Linux respectively.

E.g.,

To set a hard limit of 4096 and soft limit of 1024 in Solaris 8.

set rlim_fd_max=4096 [Refers Hard limit]
set rlim_fd_cur=1024 [Refers Soft limit]


To raise the allowed limit in Linux based distributions update either /etc/limits.conf or /etc/security/limits.conf

07 March 2008

How to Password Protect GRUB Boot loader

The main reason to password protect the GRUB boot loder is to prevent access to single user mode — If attackers can boot the system into single user mode, they are logged in automatically as root without being prompted for the root password.

To do this, open a shell prompt, log in as root, and type:

/sbin/grub-md5-crypt


When prompted, type the GRUB password and press Enter. This returns an MD5 hash of the password.

Next, edit the GRUB configuration file /boot/grub/grub.conf. Open the file and below the timeout line in the main section of the document, add the following line:

password --md5


Replace with the value returned by /sbin/grub-md5-crypt

Relative vs. Absolute Pathnames

Commands can be given file name arguments in two ways.

If you are in the same directory as the file (i.e., the file is in the current directory), then you can just enter the file name on its own (e.g., cp my_file new_file). Otherwise, you can enter the full path name, like cp /home/john/my_file /home/jack/new_file.

Very often administrators use the notation ./my_file to be clear about the distinction, for instance, cp ./my_file ./new_file. The leading ./ makes it clear that both files are relative to the current directory.

File names not starting with a / are called relative path names, and otherwise, absolute path names.

26 February 2008

Steps to Configure IP for MP-Port in HP Servers

Step 1: Connect a terminal to the console port of the system.

Step 2:
Login tothe console using username and password. The default username for MP is typically Admin and the default
password is Admin.
Step 3: Type “cm” on the MP prompt to go to the MP command menu
Step 4: Type “lc” on the MP CM prompt to modify the LAN configuration and press “A” when prompted for modification
Current LAN Configuration:
- - MAC Address : 0x001635b66433
D - DHCP Status : Disabled
I - IP Address : ---------------
M - MP Host Name: ---------------
S - Subnet Mask : ---------------
G - Gateway Address : ------------
L - Link State : Auto Negotiate
W - Web Console Port Number : 2023
- - SSH Access Port Number : - (MP Feature Not Licensed)
- - IPMI / LAN Port Number : 623A


Enter parameter(s) to change, A to modify All, or [Q] to Quit:


Step 5: Type the IP address of the MP port.

IP Address:
Current -&gt;
127.0.0.1 (default)

Modifying this parameter will cause all present LAN and Web connections to be dropped.
Enter new value, or Q to Quit: 172.16.1.100
Step 6: Type the hostname of the MP port.
Host Name:
Current -&gt;
mp001635b66433 (default)

Enter new value, or Q to Quit: m1sys100
Step 7: Type the Subnet Mask of the MP port.
Subnet Mask:
Current -&gt;
255.255.255.0 (default)

Modifying this parameter will cause all present LAN and Web connections to be dropped.

Enter new value, or Q to Quit: 255.255.224.0
Step 8: Type the Gateway of the MP port.
Gateway Address:
Current -&gt;
127.0.0.1 (default)

Enter new value, or Q to Quit: 172.16.0.1
Step 9: Press “Enter” when prompted for Web Console Port Number.
Web Console Port Number:
Current -&gt; 2023 (default)
Options: 23, 2000 to 2400

Modifying Web Port number will cause all present Web connections to be dropped.

Enter new value, or Q to Quit:

-&gt; Current Web Console Port Number has been retained

Step 10: Press “Enter” when prompted for SSH Console Port Number.
SSH Console Port Number:
Current -&gt; 22 (default)
Options: 22, 2000 to 2400

Enter new value, or Q to Quit:
-&gt; Current SSH Console Port Number has been retained
Step 11: Type “Disabled” or “D” when prompted for DHCP Status.
DHCP Status:
Current -&gt; D - Disabled
E - Enabled (default)

Modifying this parameter will cause all present LAN and Web connections to be dropped.

Enter new value, or Q to Quit: Disabled

Step 12: Press “Enter” when prompted for Link State.
Link State:
Current -&gt; A - Auto Negotiate (default)
T - 10BaseT

Modifying this parameter will cause all present LAN and Web connections to be dropped.


Enter new value, or Q to Quit:

-&gt; Current Link State has been retained

Step 13: Type “xd” on the MP CM prompt and press “r” to reset MP.
Step 14: From any of the lab machines, ping to the newly configured IP address of the GSP and see if it is alive on the
network.

21 February 2008

Online Security testing for Mail Server (SMTP)

To check whether your SMTP server reliable and fully secured.Check the URL http://www.test-smtp.com

How to Make USB Pen drive as a bootable device (RedHat)

If you cannot boot from the DVD/CD-ROM drive, but you can boot using a USB device, such as a USB pen drive, the following alternative boot method is available:

To boot using a USB pen drive, use the dd command to copy the diskboot.img image file from the /images/ directory on the DVD or CD-ROM. For example:

dd if=diskboot.img of=/dev/sda

Note: Your BIOS must support booting from a USB device in order for this boot method to work

14 February 2008

What is umask in Linux/Unix?

The User file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number .

Default umask for normal user is 0002.
Default umask for root user is 0022.

Default base permission for directories & files are 0777 (rwxrwxrwx) & 0666 (rw-rw-rw-) respectively.
To calculate directory permission for root user
Default Permissions : 777
Subtract umask value: 022 (-)
Allowed Permissions : 755

To calculate file permission for root user
Default Permissions : 666
Subtract umask value: 022 (-)
Allowed Permissions : 644

The following example explains the steps needed to set umask for permissions 700 for user files. The idea very simply only user is allowed to read or write file.
Default Permissions: 777
Subtract umask value: 077 (-)
Allowed Permissions: 700

$ umask 077
$ touch file.txt
$ ls -l file.txt

Output:

-rw------- 1 demo demo 0 2008-10-10 12:21 demo.txt

12 February 2008

Procedure to configure IP for GSP Port in HP-PA Server Models

Step 1: Connect a terminal to the console port of the system.
Step 2: Login to the console using username and password. The default username for GSP is typically root and the default password is root.
Step 3: Press Ctrl+B to go to the GSP prompt. Sometimes, it is required to press Ctrl+Ecf to get write access to the console.
Step 4: Type “lc” on the GSP prompt to modify the IP configuration and press “Y” when prompted for modification
Current configuration:
MAC Address : 0x00110a417c09
IP Address : --------------
GSP Host Name : --------------
Subnet Mask : --------------
Gateway : --------------
Web Console Port Number : 2023
Do you want to modify the LAN configuration? (Y/[N]): y
Step 5: Press “Y” when prompted to modify the Current IP Address.
Current IP Address:
Do you want to modify it? (Y/[N]): y
Step 6: Type the IP address of the GSP port and press “Y” to confirm.
New IP Address: 172.16.1.100
Confirm? (Y/[N]): y
Step 7: Press “Y” when prompted to modify the current GSP Host Name.
Current GSP Host Name:
Do you want to modify it? (Y/[N]): y
Step 8: Type the hostname of the GSP port and press “Y” to confirm
New GSP Host Name: m1sys100
Confirm? (Y/[N]): y
Step 9: Press “Y” when prompted to modify the current Subnet Mask.
Current Subnet Mask:
Do you want to modify it? (Y/[N]): y
Step 10: Type the subnet mask of the GSP port and press “Y” to confirm
Enter new Subnet Mask: 255.255.224.0
Confirm? (Y/[N]): y
Step 11: Press “Y” when prompted to modify the current Gateway.
Current Gateway:
Do you want to modify it? (Y/[N]): y
Step 12: Type the gateway of the GSP port and press “Y” to confirm.
Enter New Gateway: 172.16.0.1
Confirm? (Y/[N]): y
Step 13: Press “n” when prompted to modify the current Web Console Port.
Current Web Console Port Number: 2023
Modifying Web Port number will cause all present Web
connections to be dropped.
Do you want to modify it? (Y/[N]): n
-&gt; Reset the GSP for LAN configuration to take effect.
-&gt; Use the R option of the XD command to reset the GSP
Step 14: Type “xd” at the GSP prompt and press “r” to reset the GSP.
Step 15: From any of the lab machines, ping to the newly configured IP address of the GSP and see if it is alive on the network.