DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.


What is SUID and how to set SUID in Linux/Unix?


What is SUID and how to set it in Linux?


SUID (Set owner User ID up on execution) is a special type of file permissions given to a file. Normally in Linux/Unix when a program runs, it inherits access permissions from the logged in user. SUID is defined as giving temporary permissions to a user to run a program/file with the permissions of the file owner rather that the user who is running it. In simple words users will get file owner’s permissions as well as owner UID and GID when executing a file/program/command.

The above sentence is bit tricky and should be explained in-depth with examples.

Learn SUID with examples:

 

Example1: passwd command


When we try to change our password we will use passwd command which is owned by root. This passwd command file will try to edit some system config files such as /etc/passwd, /etc/shadow etc when we try to change our password. Some of these files cannot be opened or viewed by normal user only root user will have permissions. So if we try to remove SUID and give full permissions to this passwd command file it cannot open other files such as /etc/shadow file to update the changes and we will get permission denied error or some other error when tried to execute passwd command. So passwd command is set with SUID to give root user permissions to normal user so that it can update /etc/shadow and other files.

Example2: ping command



Similarly if we take ping command, when we have to execute this command internally it should open socket files and open ports in order to send IP packets and receive IP packets to remote server. Normal users don’t have permissions to open socket files and open ports. So SUID bit is set on this file/command so that whoever executes this will get owner (Root user’s) permissions to them when executing this command. So when this command start executing it will inherit root user permissions to this normal user and opens require socket files and ports.

Example3: crontab and at command.


When scheduling the jobs by using crontab or at command it is obvious to edit some of the crontab related configuration files located in /etc which are not writable for normal users. So crontab/at commands are set with SUID in-order to write some data.

How can I setup SUID for a file?

 

SUID can be set in two ways

1) Symbolic way(s, Stands for Set) 
2) Numerical/octal way(4)
 
Use chmod command to set SUID on file: file1.txt

Symbolic way:

chmod u+s file1.txt
Here owner permission execute bit is set to SUID with +s

Numerical way:

chmod 4750 file1.txt
 
Here in 4750, 4 indicates SUID bit set, 7 for full permissions for owner, 5 for write and execute permissions for group, and no permissions for others.

How can I check if a file is set with SUID bit or not?

Use ls –l to check if the x in owner permissions field is replaced by s or S

For example: file1.txt listing before and after SUID set

Before SUID set:

ls -l
total 8

-rwxr--r-- 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt
 
After SUID set:

ls -l
total 8

-rwsr--r-- 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt

 

Some FAQ’s related to SUID:

 

A) Where is SUID used?

1) Where root login is required to execute some commands/programs/scripts.
2) Where you don’t want to give credentials of a particular user and but want to run some programs as the owner.
3) Where you don’t want to use SUDO command but want to give execute permission for a file/script etc.

B) I am seeing “S” I.e. Capital “s” in the file permissions, what’s that?

After setting SUID to a file/folder if you see ‘S’ in the file permission area that indicates that the file/folder does not have executable permissions for that user on that particular file/folder.
For example see below example

chmod u+s file1.txt
ls -l
-rwSrwxr-x 1 surendra surendra 0 Dec 27 11:24 file1.txt
 
If you want to convert this S to s then add executable permissions to this file as show below
chmod u+x file1.txt
ls -l
-rwsrwxr-x 1 surendra surendra 0 Dec 5 11:24 file1.txt
you should see a smaller ‘s’ in the executable permission position now.


SUID with execute permissions:

SUID_Linux


SUID with out execute permissions:

SUID_Linux_without_execute_permissions

C) How can I find all the SUID set files in Linux/Unix.

find / -perm +4000
The above find command will check all the files which is set with SUID bit(4000).

D) Can I set SUID for folders?

Yes, you can if its required(you should remember one thing, that Linux treats everything as a file)

E) What is SUID numerical value?
It has the value 4

What is a sticky Bit and how to set it in Linux?

What is Sticky Bit?

Sticky Bit is mainly used on folders in order to avoid deletion of a folder and its content by other users though they having write permissions on the folder contents. If Sticky bit is enabled on a folder, the folder contents are deleted by only owner who created them and the root user. No one else can delete other users data in this folder(Where sticky bit is set). This is a security measure to avoid deletion of critical folders and their content(sub-folders and files), though other users have full permissions.

Learn Sticky Bit with examples:

 

Example: Create a project(A folder) where people will try to dump files for sharing, but they should not delete the files created by other users.
  
How can I setup Sticky Bit for a Folder?

Sticky Bit can be set in two ways
  1. Symbolic way (t,represents sticky bit)
  2. Numerical/octal way (1, Sticky Bit bit as value 1)
Use chmod command to set Sticky Bit on Folder: /opt/dump/

Symbolic way:

chmod o+t /opt/dump/
or
chmod +t /opt/dump/

Let me explain above command, We are setting Sticky Bit(+t) to folder /opt/dump by using chmod command.

Numerical way:

chmod 1757 /opt/dump/

Here in 1757, 1 indicates Sticky Bit set, 7 for full permissions for owner, 5 for read and execute permissions for group, and full permissions for others.

Checking if a folder is set with Sticky Bit or not?

Use ls –l to check if the x in others permissions field is replaced by t or T
For example: /opt/dump/ listing before and after Sticky Bit set

Before Sticky Bit set:
ls -l
total 8
-rwxr-xrwx 1 xyz xyzgroup 148 Dec 22 03:46 /opt/dump/

After Sticky Bit set:
ls -l
total 8
-rwxr-xrwt 1 xyz xyzgroup 148 Dec 22 03:46 /opt/dump/

Some FAQ’s related to Sticky Bit:

 

Now sticky bit is set, lets check if user “temp” can delete this folder which is created xyz user.

$ rm -rf /opt/dump
rm: cannot remove `/opt/dump’: Operation not permitted

$ ls -l /opt
total 8
drwxrwxrwt 4 xyz xyzgroup 4096 2012-01-01 17:37 dump
$


if you observe other user is unable to delete the folder /opt/dump. And now content in this folder such as files and folders can be deleted by their respective owners who created them. No one can delete other users data in this folder though they have full permissions.I am seeing “T” ie Capital s in the file permissions, what’s that?
After setting Sticky Bit to a file/folder, if you see ‘T’ in the file permission area that indicates the file/folder does not have executable permissions for all users on that particular file/folder.

Sticky bit without Executable permissions:




so if you want executable permissions, Apply executable permissions to the file.

chmod o+x /opt/dump/
ls -l command output:
-rwxr-xrwt 1 xyz xyzgroup 0 Dec 5 11:24 /opt/dump/

Sticky bit with Executable permissions:


sticky bit unix, unix sticky bit, suid, linux sticky bit, sticky bit in unix, sticky bit aix, sticky bit chmod, sticky bits, sticky bit linux, suid sgid sticky bit, set sticky bit, stickybit, sticky bit permission, setting sticky bit, solaris sticky bit, sticky bit solaris, sticky bit directory, remove sticky bit, ubuntu sticky bit, sticky bit t, aix sticky bit, sticky bit load balancer, directory sticky bit, umask


you should see a smaller ‘t’ in the executable permission position.
How can I find all the Sticky Bit set files in Linux/Unix.

find / -perm +1000
The above find command will check all the files which is set with Sticky Bit bit(1000).

Can I set Sticky Bit for files?
Yes, but most of the time it’s not required.

How can I remove Sticky Bit bit on a file/folder?
chmod o-t /opt/dump/

Rotating Log Files

This script moves on log files listed on the command line. It keeps all but the most recent one
compressed, and removes the last one once there are more than CYCLES of them. For example,
CYCLES=3 ; rotate messages Would have the following effects.

messages --> messages.1
messages.1 --> messages.2.gz
messages.2.gz --> messages.3.gz
messages.3.gz --> removed

script :


#!/bin/sh
# Rotate a log file and keep N copies
# Mostly stolen from inn
CYCLES=${CYCLES-5}
COMPRESS=/usr/local/bin/gzip
Z=.gz
for F in $* ; do
## Compress yesterday’s .1
test -f ${F}.1 \
&& ${COMPRESS} <${F}.1 >${F}.1${Z} \
&& rm -f ${F}.1 \
&& chmod 0440 ${F}.1${Z}
## Do rotation.
EXT=${CYCLES}
rm -f ${F}.${CYCLES}${Z}
while [ ${EXT} -gt 0 ] ; do
NEXT=${EXT}
EXT=‘expr ${EXT} - 1‘
test -f ${F].${EXT}${Z} \
&& rm -f ${F}.${NEXT}${Z} \
&& mv ${F}.${EXT}${Z} ${F}.${NEXT}${Z}
done
mv ${F} ${F}.1
done


Different RUN levels in Linux,Solaris and AIX

RedHat Linux - Run Levels 

 

0: Halt
1: Single user mode
2: Multiuser, without NFS
3: Full multiuser mode
4: Unused
5: X11
6: Reboot
 

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 ( default run level)
4: Unused
5: Completely shutdown the host (like performing a power-off @ OBP) [ thanks to Marco ]
6: Reboot but depend upon initdefault entry in /etc/inittab

AIX - Run Levels


0-1: Reserved for future use
2: Multiuser mode with NFS resources shared (default run level)
3-9: Defined according to the user's preferences
m,M,s,S: Single-user mode (maintenance level)
a,b,c: Starts processes assigned to the new run levels while leaving the existing processes at the current level running
Q,q: init command to reexamine the /etc/inittab file

Command to see Run level:-

$ who -r
Output:
. run-level 3 Mar 3 14:04 3 0 S

Solaris/Linux 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.
 
 

Runs previous command replacing the typo

when we run a command with a typo, we can correct the typo and re-run the command by the following command.

^wrong^right

Here are the examples:

The man command is wrongly typed as many
[root@test /]# many head
-bash: many: command not found


The y is replaced with empty character.
[root@test /]# ^y
man head

--------------------------------------------------------------
Here man is typed as men

[root@test /]# men head
-bash: men: command not found
the letter e is replaced with a and then the command executes.
[root@test /]# ^e^a
man head


Pushd and popd in bash

Push your present working directory to a stack that you can pop later

If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.

cd /home/complicated/path/.I/dont/want/to/forget

pushd /tmp

cd thing/in/tmp

popd (returns you to /home/complicated/path/.I/dont/want/to/forget)


awk one-liner Tips

Print column1, column5 and column7 of a data file or output of any columns list

$awk ‘{print $1, $5, $7}’ data_file

$cat file_name |awk ‘{print $1 $5 $7}’

$ls –al |awk ‘{print $1, $5, $7}’
-- Prints file_permissions,size and date

Syntax of running an awk program

Awk ‘program’ input file(s)

List all files names whose file size greater than zero.

$ls –al |awk ‘$5 > 0 {print $9}’

List all files whose file size equal to 512bytes.

$ls –al |awk ‘$5 == 512 {print $9}’

print all lines

$awk ‘{print }’ file_name

$awk ‘{print 0}’ file_name


Number of lines in a file

$awk ‘ END {print NR}’ file_name

Number of columns in each row of a file

$awk ‘ {print NF’} file_name

Sort the output of file and eliminate duplicate rows

$awk ‘{print $1, $5, $7}’ |sort –u

List all file names whose file size is greater than 512bytes and owner is "oracle"

$ls –al |awk ‘$3 == "oracle" && $5 > 512 {print $9}’

List all file names whose owner could be either "oracle" or "root"

$ls –al |awk ‘$3 == "oracle" || $3 == "root" {print $9}’

list all the files whose owner is not "oracle

$ls –al |awk ‘$3 != "oracle" {print $9}’

List all lines which has atlease one or more characters

$awk ‘NF > 0 {print }’ file_name

List all lines longer that 50 characters

$awk ‘length($0) > 50 ‘{print }’ file_name

List first two columns

$awk ‘{print $1, $2}’ file_name
Swap first two columns of a file and print

$awk ‘{temp = $1; $1 = $2; $2 = temp; print }’ file_name

Replace first column as "ORACLE" in a data file

$awk ‘{$1 = "ORACLE"; print }’ data_file
Remove first column values in a data file

$awk ‘{$1 =""; print }’ data_file

Calculate total size of a directory in Mb

$ls –al |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Calculate total size of a directory including sub directories in Mb

$ls –lR |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Find largest file in a directory including sub directories

$ls –lR |awk ‘{print $5 "\t" $9}’ |sort –n |tail -1

How to check if I am running a uniprocessor kernel or a multiprocessor kernel?

/unix is a symbolic link to the booted kernel. To find out what kernel mode is running, enter ls -l /unix and see what file /unix it links to.
The following are the three possible outputs from the ls -l /unix command and their  corresponding kernels:

/unix -> /usr/lib/boot/unix_up                                                            # 32 bit uniprocessor kernel
/unix -> /usr/lib/boot/unix_mp                                                           # 32 bit multiprocessor kernel
/unix -> /usr/lib/boot/unix_64                                                            # 64 bit multiprocessor kernel



Memory utilisation of processes in AIX

For memory information, we use the command svmon.
svmon shows the total usage of physical and paging memory.

Command to display top ten processes and users
svmon -P -v -t 10 | more

Displaying top CPU_consuming processes:
ps aux | head -1; ps aux | sort -rn +2
Displaying top memory-consuming processes:
ps aux | head -1; ps aux | sort -rn +3 | head

Displaying process in order of priority:
ps -eakl | sort -n +6 | head

Displaying the process in order of time
ps vx | head -1;ps vx | grep -v PID | sort -rn +3

Displaying the process in order of real memory use
ps vx | head -1; ps vx | grep -v PID | sort -rn +6

Displaying the process in order of I/O
ps vx | head -1; ps vx | grep -v PID | sort -rn +4


Execute a command without saving it in the history

Prepending one or more spaces to your command won't be saved in history.
It i very useful for hiding your commands which consists of passwords on the commandline.
This is tested in bash shell and works successfully.

Example :
$ echo this goes to history
this goes to history

$ echo this wont go to history
this wont go to history

$ history
1 echo this goes to history
2 history

The manual page of "bash" shows as follows:
 
 HISTCONTROL
         A  colon-separated  list of values controlling how commands are
         saved on the history list.  If  the  list  of  values  includes
         ignorespace,  lines  which begin with a space character are not
         saved in the history list.  A value of ignoredups causes  lines
         matching  the  previous history entry to not be saved.  A value
         of ignoreboth is shorthand for ignorespace and  ignoredups.   A
         value  of erasedups causes all previous lines matching the cur
         rent line to be removed from the history list before that  line
         is  saved.   Any  value  not  in the above list is ignored.  If
         HISTCONTROL is unset, or does not include a  valid  value,  all
         lines  read  by the shell parser are saved on the history list,
         subject to the value of HISTIGNORE.  The second and  subsequent
         lines  of a multi-line compound command are not tested, and are
         added to the history regardless of the value of HISTCONTROL. 
Exit without saving history

kill -9 $$

this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged

... $ ( or ${$} ) is the pid of the current bash instance

this also works perfectly in shells that don't have $ if you do something like

kill -9 `readlink /proc/self`
 

Single command to find out RAM(memory) size in Linux

You can use the command cat /proc/meminfo to get the memory details in the linux operating system.
But this gives much more information of memory.
If you need just the memory size , use the below command to get that.


cat /proc/meminfo | awk 'match($1,"MemTotal") == 1 {print $2}'

This gives the memory size in kilobytes(kb).
But I don't know if the format of /proc/meminfo varies among distribution.

 

Display Number of Processors on Linux

If you’ve just upgraded your Linux box, or you are wondering how many processors a remote server has, there’s a quick command you can use to display the number of processors.

On Linux, /proc/cpuinfo contains all of the processor information for all current processors in your computer. This will include the speed, the amount of on-chip cache, processor type, and how many cores.

Here’s the command:
cat /proc/cpuinfo | grep processor | wc -l
The command just looks in the /proc/cpuinfo file, pulls out the number of lines containing the word “processor” and passes them into wc (word count), which returns a count of the CPUs in the system.

uudecode Command


The uudecode utility reads a file or standard input if no file is specified, that includes data created by the uuencode utility. The uudecode utility scans the input file, searching for data compatible with the format specified in uuencode and attempts to create or overwrite the file described by the data. The pathname, file access permission bits and contents for the file to be produced are all contained in that data. The mode bits of the created file will be set from the file access permission bits contained in the data; that is, other attributes of the mode, including the file mode creation mask, will not affect the file being produced.

If the pathname of the file to be produced exists, and the user does not have write permission on that file, uudecode will terminate with an error. If the pathname of the file to be produced exists, and the user has write permission on that file, the existing file will be overwritten.

If the input data was produced by uuencode on a system with a different number of bits per byte than on the target system, the results of uudecode are unspecified.

Purpose

Decodes a binary file that was used for transmission using electronic mail.

Syntax

uudecode [ -o OutputFile ] [ InFile ]

Description

The uudecode command reads an encoded file, strips off leading and trailing lines added by mailers, and recreates the original file with the specified mode and name. Decoding a file causes the result to be automatically saved to a file. The file name is identical to the remote file argument originally supplied to the uuencode command unless an output file name is specified with the -o flag.

Flags

-o OutputFile Specifies the output file name that will be used instead of any pathname contained in the input data. You can direct the output of uudecode to standard output by specifying /dev/stdout as the OutputFile.

Parameters
InFile Specifies the name of the file to decode.

Example

To decode the file /tmp/con on a local system that was encoded with the follwing command:

uuencode /usr/lib/boot/unix pigmy.goat > /tmp/con

enter: uudecode /tmp/con

The file pigmy.goat will be identical to the originally encoded file /usr/lib/boot/unix.

uuencode Command


The uuencode utility writes an encoded version of the named input file, or standard input if no file is specified, to standard output. The output is encoded using the algorithm described in the STDOUT section and includes the file access permission bits (in chmod octal or symbolic notation) of the input file and the decode_pathname, for re-creation of the file on another system that conforms to this specification
 
Purpose
Encodes a binary file for transmission using electronic mail.

Syntax
 
uuencode [ -m ] [ SourceFile ] OutputFile

Description

The uuencode command converts a binary file to ASCII data. This is useful before using BNU (or uucp) mail to send the file to a remote system. The uudecode command converts ASCII data created by the uuencode command back into its original binary form.

The uuencode command takes the named SourceFile (default standard input) and produces an encoded version on the standard output. The encoding uses only printable ASCII characters, and includes the mode of the file and the OutputFile filename used for recreation of the binary image on the remote system.

Use the uudecode command to decode the file.

Flags

-m   Encode the output using the MIME Base64 algorithm. If -m is not specified, the old uuencode algorithm will be used.

Parameters 

OutputFile Specifies the name of the decoded file. You can direct the output of the uuencode command to standard output by specifying /dev/stdout as the OutputFile.
SourceFile Specifies the name of the binary file to convert. Default is standard input.

Examples

To encode the file unix on the local system and mail it to the user jsmith on another system called mysys, enter: uuencode unix unix | mail jsmith@mysys


To encode the file /usr/lib/boot/unix on your local system with the name pigmy.goat in the file /tmp/con , enter: uuencode /usr/lib/boot/unix pigmy.goat > /tmp/con


SUDO in UNIX

Sudo is a standard way to give users some administrative rights without giving out the root
password. Sudo is very useful in a multi user environment with a mix of server and
workstations. Simply call the command with sudo:

# sudo /etc/init.d/dhcpd restart                                   # Run the rc script as root
# sudo -u sysadmin whoami                                       # Run cmd as an other user

 Configuration :

Sudo is configured in /etc/sudoers and must only be edited with visudo. The basic syntax is
(the lists are comma separated):

user hosts = (runas) commands                                   # In /etc/sudoers
users one or more users or %group (like %wheel) to gain the rights
hosts list of hosts (or ALL)
runas list of users (or ALL) that the command rule can be run as. It is enclosed in ( )!
commands list of commands (or ALL) that will be run as root or as (runas)
Additionally those keywords can be defined as alias, they are called User_Alias, Host_Alias,
Runas_Alias and Cmnd_Alias. This is useful for larger setups.

Here a sudoers example:

# cat /etc/sudoers

# Host aliases are subnets or hostnames.
Host_Alias DMZ = 212.118.81.40/28
Host_Alias DESKTOP = work1, work2

# User aliases are a list of users which can have the same rights

User_Alias ADMINS = colin, luca, admin
User_Alias DEVEL = joe, jack, julia
Runas_Alias DBA = oracle,pgsql

# Command aliases define the full path of a list of commands
Cmnd_Alias SYSTEM = /sbin/reboot,/usr/bin/kill,/sbin/halt,/sbin/shutdown,/etc/init.d/
Cmnd_Alias PW = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root           # Not root pwd!
Cmnd_Alias DEBUG = /usr/sbin/tcpdump,/usr/bin/wireshark,/usr/bin/nmap

# The actual rules
root,ADMINS ALL = (ALL) NOPASSWD: ALL             # ADMINS can do anything w/o a password.
DEVEL DESKTOP = (ALL) NOPASSWD: ALL             # Developers have full right on desktops
DEVEL DMZ = (ALL) NOPASSWD: DEBUG                 # Developers can debug the DMZ servers.

# User sysadmin can mess around in the DMZ servers with some commands.
sysadmin DMZ = (ALL) NOPASSWD: SYSTEM,PW,DEBUG
sysadmin ALL,!DMZ = (ALL) NOPASSWD: ALL            # Can do anything outside the DMZ.
%dba ALL = (DBA) ALL # Group dba can run as database user.
# anyone can mount/unmount a cd-rom on the desktop machines
ALL DESKTOP = NOPASSWD: /sbin/mount /cdrom,/sbin/umount /cdrom

Difference between /etc/hosts and /etc/resolv.conf

/etc/resolv.conf specifies the nameservers for resolver lookups, where it will actual use the DNS protocol for resolving the hostnames.
Typically the /etc/hosts file is used for administrative purposes such as backend and internal functions, which is substantially more isolated in scope, as only the local server will reference it it.

/etc/nsswitch.conf
specifies the lookup order with the hosts entry.

If this does not answer your question, please clarify further.

Look at the following manpages:

/etc/resolv.conf
specifies nameservers in order of search preference.
/etc/hosts overrides all nameservers by mapping urls/shortnames to IPs.


Extracting snap.pax.Z file - AIX

 For basic dump analysis, this article is mostly interested in a dump image. Here, we cover how to extract the appropriate files from the snap package and then explain a methodical approach to examine the dump, and find the fundamental reason for a system crash. The dump file and the UNIX® file are in the dump subdirectory of the snap package.

Though we are primarily focused on the dump image, it is important to note that snap can provide you with useful information when used with appropriate options. Additional information is found in the General and Kernel subsections of the article.

General

This general directory includes information about the system runtime environment, for example:

  •     Copy of ODM data.
  •     All environment variables (e.g., PATH and TZ).
  •     Date and time the data was collected.
  •     Amount of real memory on the system (bootinfo -r).
  •     Listing of all defined paging spaces.
  •     Listing of all installed filesets and their levels.
  •     Listing of all installed APARs.
  •     Device attributes (lsattr -El).
  •     System VPD information (lscfg -pv).
  •     Status of last dump (sysdumpdev -L).

Kernel

The kernel subdirectory contains useful kernel information (Process and memory data).

  •     Date and time the data was collected
  •     Vmstat output
  •     VMM tunable information (vmo -L).
  •     Scheduling tunable information (schedo -L).
  •     I/O related tunable iformation (ioo -L).
  •     Environment variables.
  •     SRC information (lssrc -a).
  •     Process information (ps -ef and ps -leaf).
  •     Checksum of device drivers and methods.

Extracting the snap package

The pax command is used to extract files from the snap package.

    To view the contents of a snap package, type:

    # zcat snap.pax.Z | pax -v


    To extract the entire contents of a package, type:

     # zcat snap.pax.Z | pax -r


    To extract just the dump, general, and kernel subdirectories, type:

     #uncompress snap.pax.Z
     #zcat snap.pax.Z | pax -r ./dump ./general ./kernel

Open Source with AIX

AIX has a large range of Open Source tools, and applications already ported and packaged ready for you to install. This makes it far easier and quick to get Open Source tools and applications working and useful on AIX. All the big popular Open Source stuff is available. My favourites that are in the first URL below are:

  • Apache - web server the one that runs the web
  • emacs - editor and so much more
  • ethereal - network monitoring by packets, protocol, contents
  • Ganglia - cluster performance monitoring and graphing
  • GNC GCC - compiler collection particularly C and C++
  • gimp - image manipulation
  • Gnome - desktop
  • KDE - desktop
  • gzip - file compression utility
  • MySQL - the database
  • PHP - scripting, good for web servers
  • rdist - file distribution
  • Samba - Windows filesystem and printing and much more
  • rxvt - colour xterm
  • squid - proxy server
  • vim - improved vi editor for colourised syntax highlighing
  • VNC - Virtual Network Computing X windows on any machine (even Windows!!)
  • wget - checking and copying websites

Well, your list might be different but there are hundreds of them available. You can, of course, download the original source code and compile it yourself but this means you will need the compilers (most use the GNC compilers), some programing skills and time to read up on the options and build process. then you need to perform some testing to prove it is all working.
Hint: I always compile with the latest GNU compilers to avoid problems.

Installation specific commands in AIX

Below are the commands which are related to the installation in aix.


lslpp -l To see the details of installed file sets


lslpp -ha bos.net.* To list the installation history of all file set in bos.net packages


lslpp -f bos.rte To list the files in the bos.rte package


lslpp -w /etc/hosts To list the file set which contain /etc/hosts file (parent fileset)


lslpp -p bos.net.nfs.server To list the pre requisites for bos.net.nfs.server file set 


lslpp -d To show dependancies of fileset
          
installp -L -d /dev/rmt0.1 To list the installable products on the device rmt0


installp -aX -d /dev/rmt0.1 bos.net To install all filesets within bos.net and expands file system if it requires


installp -u bos.net To remove bos.net


installp -r To reject the applied software


installp -c -f To commit the applied fileset


installp -C To cleanup an incomplete installation


lppchk -c To check the fileset items and verifies that the checksum and filesize are consistent with SWVPD


lppchk -v verify that all filesets have required requisites and are completely installed


instfix -k IX9999 -d /dev/rmt0.1 To install the file set associated with fix IX9999 from rmt0


instfix -ik IX9999 To verify fix IX9999 installed


Paging space commands in AIX

Below are the commands related to the paging space in AIX.


lsps -a To list out all paging spaces


lsps hd6 To display the details of the paging space hd6


chps -a y paging00 To turn on the paging space paging00 on next reboot


chps -a n paging00 To turn off the paging space paging00 on next reboot


chps -s4 paging00 To increase the size of the paging space in 4 LP blocks


mkps -a -n -s4 newvg To create a paging space on VG newvg of 4 LP size (-s4) and activate it immediately (-n) and activate it at every restarts


rmps paging00 To remove the paging space paging00


swapon -a To invoke all entries in /etc/swapspaces file


swapon /dev/paging00 To make available swap space paging00


swapoff /dev/paging00 To disable swap space paging00



Disable telnet in AIX

The procedure to disable telnet in AIX is as follows:

#vi /etc/inetd.conf

comment out telnet from this file (#telnet ... ... .. )

save it and

#refresh -s inetd

Then telnet session will be disabled in that server from now

Filesystem commands in AIX

lsfs Lists all filesystems in the /etc/filesystems entry


lsfs -a To list all filesystems (default)


lsfs -q List all filesystems with detailed info (shows size of FS and LV in it. so we can check whether size of LV=size os FS)


lsfs -l Specify the output in list format


lsfs -c Specify the output in column format


lsfs -v jfs Lists all jfs filesystems


chfs -a size=24576 /test Change size of FS /test to 24576(blocks)x 512 bytes  (12 MB)


chfs -a size=+24576 /test Add 24576(blocks)x512 byte  to FS /test


chfs -a size=+64M /test Add 64 MB to /test


chfs -a size=10G /test fix size of the FS /test to 10 GB


chfs -m /test /new Change the mount point from /test to /new


chfs -A /test To auto mount the filesystem test


chfs -d account /test Remove account attribute of /test.(from /etc/filesystems file)


chfs -a splitcopy=/backup -a copy=2 /oracle This will mount the 2nd copy of mirrored filesystem oracle to /backup in read-only mode for backup purpose


crfs -v jfs2 -g newvg -a size=100M -m /test Creates FS /test of type jfs in VG newvg of size 100 MB with default LV.


crfs -v jfs -d /dev/lv00 -m /test Create FS /test of type jfs on device /dev/lv00


rmfs /test Deletes FS /test and associated LV


rmfs -r /test Deletes FS /test its mount point and associated LV


defragfs /test To defragment the file system /test


defragfs -q /test Display the current defrag status of the file system


fsck -y n /dev/lv00 To check the filesystem associated to /dev/lv00 assuming response "yes"


fsck -p /dev/lv00 To restore superblock from backup superblock




Recreate BOOT LOGICAL VOLUME (BLV) in AIX



If a Boot Logical volume (BLV) is corrupted, a machine will not boot.
(Eg:bad block in a disk might cause a corrupted BLV)

To fix this situation, You must boot your machine in maintenance mode, from a CD or Tape. If a NIM has been setup for a machine, you can also boot the machine from a NIM master in maintenance mode.

The bootlists are set using the bootlist command or through the System Management Services Progam (SMS). pressing F1 will go to SMS Mode.

then change the bootlist for service(maintenance) mode as 1st device to CD ROM.

#bootlist -m service cd0 hdisk0 hdisk1

then start maintenance mode for system recovery,

Access rootvg,

access this volume group to start a shell,

then recreate BLV using bosboot command.

#bosboot -ad /dev/hdisk0

it's important that you do a proper shutdown, All changes need to be written from memory to disk.

#shutdown -Fr

Imp: bosboot command requires that boot logical volume hd5 exists. If you wan create a BLV ( may be it had been deleted by mistake ), do the following,

1. Boot your machine in maintenance mode,
2. Create a new hd5 logical volume, one PP size, must be in rootvg,specify boot as logical volume type,

#mklv -y hd5 -t boot rootvg 1

3. Then run bosboot command as described.

If you have an HMC, then at the time of booting select boot as SMS in the menu

Turbocharge PuTTY with 12 Powerful Add-Ons

PuTTY Logo PuTTY is hands-down the best, free, and lightweight SSH client for Windows. I have provided list of 12 powerful PuTTY add-ons with screenshots, that will solve few shortcomings of the original PuTTY.  Play around with these add-ons and choose the one that suites your need.


1. PuTTY Connection Manager

PuTTYCM gives a nice feature to arrange several PuTTY sessions in tabs . While starting PuTTYCM for the first time, you should specify the location of the original PuTTY. This requires .NET 2.0 to be installed on the windows system. Following screen-shot displays three putty sessions in tabs within the same window.
Note: If the PuTTY Connection Manager opens the original PuTTY in a separate window, instead of opening as a TAB, please go to Tools -> Options -> Select the check-box “Enable additional timing for PuTTY capture (ms)” -> set the value to 300 ms. This will open the PuTTY window inside the TAB as shown below.

Note: Refer to the PuTTY Connection Manager Tutorial for more details on the PuTTY CM features.

PuTTY Connection Manager - Multiple Tab
Fig – PuTTY Connection Manager with multiple Tabs

2. PuTTYcyg

Cygwin users will absolutely love PuTTYcyg. This lets you use PuTTY as a local cygwin terminal. If you use cygwin on your windows, I’m sure you’ll hate the default MS-DOS looking cygwin window. Using PuTTYcyg, you can run cygwin inside PuTTY. I love this add-on and use it for my cygwin on Windows.
On PuTTYcyg, click on cygterm radio button in the Connection type. Enter – (hyphen) in the “Command (use – for login shell“, to connect to the cygwin on the windows laptop using PuTTY as shown below.

PuTTYcyg Cygterm radio-button
Fig – PuTTYcyg with Cygterm option

3. PuTTYtray

Using PuTTYtray, you can minimize the PuTTY window to the system tray on windows. By default, original PuTTY stores the session information in the registry. This is painful, when you want to transfer PuTTY sessions from one laptop to another. In PuTTYtray, there is an additional radio button “Sessions from file” as shown below, that will let you store session information in a file.

PuTTYtray
Fig – PuTTYtray with “Session from file” option

4. PuttyTabs

PuttyTabs provides a floating bar, that will display the open PuTTY sessions in TABs. Clicking on one of the tabs will bring the respective PuTTY session to the foreground. While starting PuTTYTabs for the first time, you should specify location of the original PuTTY. It reads the windows registry to get all the available PuTTY sessions. This also requires .NET 2.0 to be installed on the windows system. Following screen-shot displays three putty sessions arranged in tab.


PuTTYTabs Screenshot
Fig – PuTTYTabs with multiple Tabs

5. Quest PuTTY

Quest Software modified the PuTTY to add Active Directory (GSSAPI Kerberos) single sign-on feature. Quest PuTTY uses Microsoft’s Security Service Provider Interface (SSPI), which is Microsoft’s version of the GSSAPI, with which it is wire compatible. This version of PuTTY adds a new menu-item called GSSAPI, under Connection -> SSH, as shown below.

Quest PuTTY with GSSAPI
Fig – Quest PuTTY with GSSAPI option

6. Modified PuTTY

This modified PuTTY stores the PuTTY sessions in folder instead of storing it in the registry. If you already have sessions stored in the registry, it will display those also. The sessions stored in registry will be marked as [registry] as shown below. When you create a session using this PuTTY, this creates a sub-folder called session in the same folder where putty.exe is located, to store all the sessions in the file.

Modified Putty
Fig – Modified Putty displaying both registry and file sessions

7. PocketPuTTY

PocketPuTTY runs on Windows Mobile 2003/5.0 operating system. After I got my blackberry, I have dumped my Dell Axim that was running on Windows Mobile. So, I have not tried PocketPuTTY myself. If you’ve used PocketPuTTY or other mobile version of PuTTY, please leave your feedback.

PocketPuTTY UI
Fig – PocketPuTTY for Windows Mobile

Note: If you are using blackberry phone, refer to Blackberry PuTTY Tutorial for installing and configuring PuTTY on blackberry.

8. portaPuTTY

portaPuTTY is a modified version of the PuTTY that stores the session information in a file by default, instead of storing it in the windows registry. The session files are stored under .putty/sessions folder. The .putty folder is created under the same directory where the putty.exe is located.

9. PuTTY Portable

PuTTY Portable is part of PortableApps suite. Use this to launch PuTTY from the USB drive and carry the sessions along with you.

10. PuTTY Launchy Plugin

If you are using Launchy, the open source keystroke launcher for windows, you can use Putty Launchy Plugin, to launch putty sessions from Launchy very easily. i.e you can type “ssh” or “putty” followed by tab or space to list all of your PuTTY sessions. Once you select a particular session, Launchy will automatically launch that particular PuTTY session.

PuTTY Launchy Plugin
Fig – PuTTY Launchy Plugin. Type ssh followed by tab.

11. PuTTY Session Manager

PuTTY Session Manager will let you organize the PuTTY sessions into folders and assign hotkeys. This requires Microsoft .NET 2.0. Right click on the PSM icon in the system track and select “Session Hotkeys” to assign hot-keys for PuTTY session as shown below.

PuTTY Session Manager Hot Key Assignment
Fig – PuTTY Session Manager with session hot-key
To create a folder, right click on a particular PuTTY session -> Session Management -> New Folder. To move a existing session to a folder, just drag the session and drop to the corresponding folder.

PSM Session List with folders
Fig – PuTTY Session Manager with sessions inside sub-folder

12. PuTTY Command Sender

PuTTYCS is very helpful little tool that can boost your productivity by eliminating repetitive tasks performed on different servers. Using PuTTYCS, you can send a unix command to multiple PuTTY windows at the same time. You can use this to backup files, view log files, start and stop processes, copying file etc., on multiple servers, just by executing the command once, as shown below.

PuTTY Command Sender
Fig – PuTTYCS sends unix command to multiple PuTTY session