April 30, 2009

Changing your login screen!!!!!!!!!!!!

You will find ample of web-sites having Various Desktop Themes and Login Manager Themes. Just Search in Google and thousands of results will be available to you. Just to reduce your work go to:

http://art.gnome.org

Its an excellent site.

Here you will get ample of Desktop backgrounds, Icons, Splash Screens, Login Manager Themes etc.

Download any login manager from the various themes available under Login Manager Section which is present under Desktop Themes.

I downloaded Morning-Light theme Login manager which had file of following format:

GDM-Morning.tar.bz2

Configuring it is very simple task.

Just find the section called “Login Screen”. Most Probably you will find it under “system settings”.

Click on it. On the Local menu, click the Add button and select the theme you wanna install. After installing the theme, select your new theme and close the window.Now logout the desktop and enjoy the new login manager.

April 25, 2009

Some Linux Interview Questions !!!!!

Q1. You need to see the last fifteen lines of the files dog, cat and horse. What command should you use?
tail -15
Ans: The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines of each specified file.

Q2. Who owns the data dictionary?

Ans: The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the database is created.

Q3. You routinely compress old log files. You now need to examine a log from two months ago. In order to view its contents without first having to decompress it, use the _________ utility.

Ans: zcat

The zcat utility allows you to examine the contents of a compressed file much the same way that cat displays a file.

Q4. You suspect that you have two commands with the same name as the command is not producing the expected results. What command can you use to determine the location of the command being run?

Ans: which

The which command searches your path until it finds a command that matches the command you are looking for and displays its full path.

Q5. You locate a command in the /bin directory but do not know what it does. What command can you use to determine its purpose.

Ans: whatis

The whatis command displays a summary line from the man page for the specified command.

Q6. You wish to create a link to the /data directory in bob's home directory so you issue the command ln /data /home/bob/datalink but the command fails. What option should you use in this command line to be successful.

Ans: Use the -F option

In order to create a link to a directory you must use the -F option.

Q7. When you issue the command ls -l, the first character of the resulting display represents the file's ___________.

Ans: type

The first character of the permission block designates the type of file that is being displayed.

Q8. What utility can you use to show a dynamic listing of running processes? __________

Ans: top

The top utility shows a listing of all running processes that is dynamically updated.

Q9. Where is standard output usually directed?

Ans: to the screen or display

By default, your shell directs standard output to your screen or display.

Q10. You wish to restore the file memo.ben which was backed up in the tarfile MyBackup.tar. What command should you type?

Ans: tar xf MyBackup.tar memo.ben

This command uses the x switch to extract a file. Here the file memo.ben will be restored from the tarfile MyBackup.tar.

Q11. You need to view the contents of the tarfile called MyBackup.tar. What command would you use?

Ans: tar tf MyBackup.tar

The t switch tells tar to display the contents and the f modifier specifies which file to examine.

Q12. You want to create a compressed backup of the users' home directories. What utility should you use?

Ans: tar

You can use the z modifier with tar to compress your archive at the same time as creating it.

Q13. What daemon is responsible for tracking events on your system?

Ans: syslogd

The syslogd daemon is responsible for tracking system information and saving it to specified log files.

Q14. You have a file called phonenos that is almost 4,000 lines long. What text filter can you use to split it into four pieces each 1,000 lines long?

Ans: split

The split text filter will divide files into equally sized pieces. The default length of each piece is 1,000 lines.

Q15. You would like to temporarily change your command line editor to be vi. What command should you type to change it?

Ans: set -o vi

The set command is used to assign environment variables. In this case, you are instructing your shell to assign vi as your command line editor. However, once you log off and log back in you will return to the previously defined command line editor.



Q16. What account is created when you install Linux?

Ans: root

Whenever you install Linux, only one user account is created. This is the superuser account also known as root.

Q17. What command should you use to check the number of files and disk space used and each user's defined quotas?

Ans: repquota

The repquota command is used to get a report on the status of the quotas you have set including the amount of allocated space and amount of used space.

In order to run fsck on the root partition, the root partition must be mounted as
readonly .You cannot run fsck on a partition that is mounted as read-write.

Q18. In order to improve your system's security you decide to implement shadow passwords. What command should you use?

Ans: pwconv

The pwconv command creates the file /etc/shadow and changes all passwords to 'x' in the /etc/passwd file.

Q19. Bob Armstrong, who has a username of boba, calls to tell you he forgot his password. What command should you use to reset his command?

Ans: passwd boba

The passwd command is used to change your password. If you do not specify a username, your password will be changed.



Q20. What command should you type to see all the files with an extension of 'mem' listed in reverse alphabetical order in the /home/ben/memos directory.

Ans: ls -r /home/ben/memos/*.mem

The -c option used with ls results in the files being listed in chronological order. You can use wildcards with the ls command to specify a pattern of filenames.

Q21. What file defines the levels of messages written to system log files?

Ans: kernel.h

To determine the various levels of messages that are defined on your system, examine the kernel.h file.

Q22. What command is used to remove the password assigned to a group?

Ans: gpasswd -r

The gpasswd command is used to change the password assigned to a group. Use the -r option to remove the password from the group.

Q23. What command would you type to use the cpio to create a backup called backup.cpio of all the users' home directories?

Ans: find /home | cpio -o > backup.cpio

The find command is used to create a list of the files and directories contained in home. This list is then piped to the cpio utility as a list of files to include and the output is saved to a file called backup.cpio.

Q24. What can you type at a command line to determine which shell you are using?

Ans: echo $SHELL

The name and path to the shell you are using is saved to the SHELL environment variable. You can then use the echo command to print out the value of any variable by preceding the variable's name with $. Therefore, typing echo $SHELL will display the name of your shell.



Q25. What type of local file server can you use to provide the distribution installation materials to the new machine during a network installation?

A) Inetd
B) FSSTND
C) DNS
D) NNTP
E) NFS

Ans: E - You can use an NFS server to provide the distribution installation materials to the machine on which you are performing the installation.

Answers a, b, c, and d are all valid items but none of them are file servers. Inetd is the superdaemon which controls all intermittently used network services. The FSSTND is the Linux File System Standard. DNS provides domain name resolution, and NNTP is the transfer protocol for usenet news.



Q26. If you type the command cat dog & > cat what would you see on your display? Choose one:
a. Any error messages only.
b. The contents of the file dog.
c. The contents of the file dog and any error messages.
d. Nothing as all output is saved to the file cat.

Ans: d

When you use & > for redirection, it redirects both the standard output and standard error. The output would be saved to the file cat.


Q27. You are covering for another system administrator and one of the users asks you to restore a file for him. You locate the correct tarfile by checking the backup log but do not know how the directory structure was stored. What command can you use to determine this?

Choose one:
a. tar fx tarfile dirname
b. tar tvf tarfile filename
c. tar ctf tarfile
d. tar tvf tarfile

Ans: d

The t switch will list the files contained in the tarfile. Using the v modifier will display the stored directory structure.

Q28. You have the /var directory on its own partition. You have run out of space. What should you do? Choose one:
a. Reconfigure your system to not write to the log files.
b. Use fips to enlarge the partition.
c. Delete all the log files.
d. Delete the partition and recreate it with a larger size.

Ans: d

The only way to enlarge a partition is to delete it and recreate it. You will then have to restore the necessary files from backup.

Q29. You have a new application on a CD-ROM that you wish to install. What should your first step be?
Choose one:
a. Read the installation instructions on the CD-ROM.
b. Use the mount command to mount your CD-ROM as read-write.
c. Use the umount command to access your CD-ROM.
d. Use the mount command to mount your CD-ROM as read-only.

Ans: d

Before you can read any of the files contained on the CD-ROM, you must first mount the CD-ROM..

Q30. Which password package should you install to ensure that the central password file couldn't be stolen easily?
A) PAM
B) tcp_wrappers
C) shadow
D) securepass
E) ssh

Ans: C - The shadow password package moves the central password file to a more secure location. Answers a, b, and e all point to valid packages, but none of these places the password file in a more secure location. Answer d points to an invalid package.


Q31. When using useradd to create a new user account, which of the following tasks is not done automatically.
Choose one:

a. Assign a UID.
b. Assign a default shell.
c. Create the user's home directory.
d. Define the user's home directory.

Ans: c

The useradd command will use the system default for the user's home directory. The home directory is not created, however, unless you use the -m option.


Q32. You want to enter a series of commands from the command-line. What would be the quickest way to do this?
Choose One

a. Press enter after entering each command and its arguments
b. Put them in a script and execute the script
c. Separate each command with a semi-colon (;) and press enter after the last command
d. Separate each command with a / and press enter after the last command

Ans:
c

The semi-colon may be used to tell the shell that you are entering multiple commands that should be executed serially. If these were commands that you would frequently want to run, then a script might be more efficient. However, to run these commands only once, enter the commands directly at the command line.


Q33. You attempt to use shadow passwords but are unsuccessful. What characteristic of the /etc/passwd file may cause this?
Choose one:

a. The login command is missing.
b. The username is too long.
c. The password field is blank.
d. The password field is prefaced by an asterisk.

Ans: c

The password field must not be blank before converting to shadow passwords.

Q34. When you install a new application, documentation on that application is also usually installed. Where would you look for the documentation after installing an application called MyApp?

Choose one:
a. /usr/MyApp
b. /lib/doc/MyApp
c. /usr/doc/MyApp
d. In the same directory where the application is installed.

Ans: c

The default location for application documentation is in a directory named for the application in the /usr/doc directory.

Q35. What file would you edit in your home directory to change which window manager you want to use?
A) Xinit
B) .xinitrc
C) XF86Setup
D) xstart
E) xf86init

Ans: B - The ~/.xinitrc file allows you to set which window man-ager you want to use when logging in to X from that account.
Answers a, d, and e are all invalid files. Answer c is the main X server configuration file.


Q36. What command allows you to set a processor-intensive job to use less CPU time?
A) ps
B) nice
C) chps
D) less
E) more

Ans: B - The nice command is used to change a job's priority level, so that it runs slower or faster. Answers a, d, and e are valid commands but are not used to change process information. Answer c is an invalid command.


Q37. While logged on as a regular user, your boss calls up and wants you to create a new user account immediately. How can you do this without first having to close your work, log off and logon as root?

Choose one:
a. Issue the command rootlog.
b. Issue the command su and type exit when finished.
c. Issue the command su and type logoff when finished.
d. Issue the command logon root and type exit when finished.

Ans: b

You can use the su command to imitate any user including root. You will be prompted for the password for the root account. Once you have provided it you are logged in as root and can do any administrative duties.


Q38. There are seven fields in the /etc/passwd file. Which of the following lists all the fields in the correct order?
Choose one:

a. username, UID, GID, home directory, command, comment
b. username, UID, GID, comment, home directory, command
c. UID, username, GID, home directory, comment, command
d. username, UID, group name, GID, home directory, comment

Ans: b

The seven fields required for each line in the /etc/passwd file are username, UID, GID, comment, home directory, command. Each of these fields must be separated by a colon even if they are empty.

Q39. Which of the following commands will show a list of the files in your home directory including hidden files and the contents of all subdirectories?

Choose one:
a. ls -c home
b. ls -aR /home/username
c. ls -aF /home/username
d. ls -l /home/username

Ans: b

The ls command is used to display a listing of files. The -a option will cause hidden files to be displayed as well. The -R option causes ls to recurse down the directory tree. All of this starts at your home directory.

Q40. In order to prevent a user from logging in, you can add a(n) ________at the beginning of the password field.

Ans: asterick

If you add an asterick at the beginning of the password field in the /etc/passwd file, that user will not be able to log in.

Q41. You have a directory called /home/ben/memos and want to move it to /home/bob/memos so you issue the command mv /home/ben/memos /home/bob. What is the results of this action?

Choose one:
a. The files contained in /home/ben/memos are moved to the directory /home/bob/memos/memos.
b. The files contained in /home/ben/memos are moved to the directory /home/bob/memos.
c. The files contained in /home/ben/memos are moved to the directory /home/bob/.
d. The command fails since a directory called memos already exists in the target directory.

Ans: a

When using the mv command to move a directory, if a directory of the same name exists then a subdirectory is created for the files to be moved.

Q42. Which of the following tasks is not necessary when creating a new user by editing the /etc/passwd file?
Choose one:

a. Create a link from the user's home directory to the shell the user will use.
b. Create the user's home directory
c. Use the passwd command to assign a password to the account.
d. Add the user to the specified group.

Ans: a

There is no need to link the user's home directory to the shell command. Rather, the specified shell must be present on your system.

Q43. You issue the following command useradd -m bobm But the user cannot logon. What is the problem?
Choose one:

a. You need to assign a password to bobm's account using the passwd command.
b. You need to create bobm's home directory and set the appropriate permissions.
c. You need to edit the /etc/passwd file and assign a shell for bobm's account.
d. The username must be at least five characters long.

Ans: a

The useradd command does not assign a password to newly created accounts. You will still need to use the passwd command to assign a password.

Q44. You wish to print the file vacations with 60 lines to a page. Which of the following commands will accomplish this? Choose one:
a. pr -l60 vacations | lpr
b. pr -f vacations | lpr
c. pr -m vacations | lpr
d. pr -l vacations | lpr

Ans: a

The default page length when using pr is 66 lines. The -l option is used to specify a different length.

Q45. Which file defines all users on your system?
Choose one:

a. /etc/passwd
b. /etc/users
c. /etc/password
d. /etc/user.conf

Ans: a

The /etc/passwd file contains all the information on users who may log into your system. If a user account is not contained in this file, then the user cannot log in.


Q46. Which two commands can you use to delete directories?
A) rm
B) rm -rf
C) rmdir
D) rd
E) rd -rf

Ans(s): B, C - You can use rmdir or rm -rf to delete a directory. Answer a is incorrect, because the rm command without any specific flags will not delete a directory, it will only delete files. Answers d and e point to a non-existent command.


Q47. Which partitioning tool is available in all distributions?
A) Disk Druid
B) fdisk
C) Partition Magic
D) FAT32
E) System Commander

Ans(s): B - The fdisk partitioning tool is available in all Linux distributions.

Answers a, c, and e all handle partitioning, but do not come with all distributions. Disk Druid is made by Red Hat and used in its distribution along with some derivatives. Partition Magic and System Commander are tools made by third-party companies. Answer d is not a tool, but a file system type. Specifically, FAT32 is the file system type used in Windows 98.


Q48. Which partitions might you create on the mail server's hard drive(s) other than the root, swap, and boot partitions?
[Choose all correct answers]

A) /var/spool
B) /tmp
C) /proc
D) /bin
E) /home

Ans(s): A, B, E - Separating /var/spool onto its own partition helps to ensure that if something goes wrong with the mail server or spool, the output cannot overrun the file system. Putting /tmp on its own partition prevents either software or user items in the /tmp directory from overrunning the file system. Placing /home off on its own is mostly useful for system re-installs or upgrades, allowing you to not have to wipe the /home hierarchy along with other areas. Answers c and d are not possible, as the /proc portion of the file system is virtual-held in RAM-not placed on the hard drives, and the /bin hierarchy is necessary for basic system functionality and, therefore, not one that you can place on a different partition.


Q49. What utility can you use to automate rotation of logs?

Ans: logrotate

The logrotate command can be used to automate the rotation of various logs.

Q50. In order to display the last five com mands you have entered using the history command, you would type ___________ .

Ans
: history 5

The history command displays the commands you have previously entered. By passing it an argument of 5, only the last five commands will be displayed.

Q51. What command can you use to review boot messages?

Ans: dmesg

The dmesg command displays the system messages contained in the kernel ring buffer. By using this command immediately after booting your computer, you will see the boot messages.

Q52. What is the minimum number of partitions you need to install Linux?

Ans: 2

Linux can be installed on two partitions, one as / which will contain all files and a swap partition.

Q53. What is the name and path of the main system log?

Ans: /var/log/messages

By default, the main system log is /var/log/messages.

Q54. The top utility can be used to change the priority of a running process? Another utility that can also be used to change priority is ___________?


Ans: nice

Both the top and nice utilities provide the capability to change the priority of a running process.

Understanding /etc/passwd File Format !!!!

Q. Can you explain /etc/passwd file format for Linux and UNIX operating systems?

A. /etc/passwd file stores essential information, which is required during login i.e. user account information.

/etc/passwd is a text file, that contains a list of the system's accounts, giving for each account some useful information like user ID, group ID, home directory, shell, etc. It should have general read permission as many utilities, like ls use it to map user IDs to user names, but write access only for the superuser (root).

Understanding fields in /etc/passwd

The /etc/passwd contains one entry per line for each user (or user account) of the system. All fields are separated by a colon (:) symbol. Total seven fields as follows.

Generally, passwd file entry looks as follows (click to enlarge image):

1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.

2. Password: An x character indicates that encrypted password is stored in /etc/shadow file.

3. User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.

4. Group ID (GID): The primary group ID (stored in /etc/group file)

5. User ID Info: The comment field. It allow you to add extra information about the users such as user's full name, phone number etc. This field use by finger command.

6. Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /

7. Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell. Please note that it does not have to be a shell.

/etc/passwd is only used for local users only. To see list of all users, enter:
$ cat /etc/passwd

To search for a username called vinod, enter:
$ grep vinod /etc/passwd
/etc/passwd file permission

The permission on the /etc/passwd file should be read only to users (-rw-r--r--) and the owner must be root:
$ ls -l /etc/passwd
Output:

-rw-r--r-- 1 root root 2659 Sep 17 01:46 /etc/passwd

Your password is stored in /etc/shadow file

Your encrpted password is not stored in /etc/passwd file. It is stored in /etc/shadow file. In the good old days there was no great problem with this general read permission. Everybody could read the encrypted passwords, but the hardware was too slow to crack a well-chosen password, and moreover, the basic assumption used to be that of a friendly user-community.

Almost, all modern Linux / UNIX line operating systems use some sort of the shadow password suite, where /etc/passwd has asterisks (*) instead of encrypted passwords, and the encrypted passwords are in /etc/shadow which is readable by the superuser only.

Redhat Linux Internet Connection Sharing !!!!

Q. How do I configure Redhat Linux computer to share my internet connection? How do I configure RHEL as a software router with two interfaces? How do I share my single connection with other PCs on LAN?

A. Linux can be easily configured to share an internet connection using iptables. All you need is two network interface cards as follows:
a) Your internal (LAN) network connected via eth0 with static ip address 192.168.1.254
b) Your external WAN) network is connected via eth1 with static ip address 192.168.2.1

Please note that interface eth1 may have public IP address or IP assigned by ISP.

Step # 1: Enable Packet Forwarding

Login as the root user. Open /etc/sysctl.conf file
# vi /etc/sysctl.conf


Add the following line to enable packet forwarding for IPv4:
net.ipv4.conf.default.forwarding=1


Save and close the file.

Restart networking:
# service network restart

Step # 2: Enable IP masquerading

In Linux networking, Network Address Translation (NAT) or Network Masquerading (IP Masquerading) is a technique of transceiving network traffic through a router that involves re-writing the source and/or destination IP addresses and usually also the TCP/UDP port numbers of IP packets as they pass through. In short, IP masquerading is used to share the internet connection.

Share internet connection

To share network connection via eth1, enter the following rule at command prompt (following useful for ppp0 or dial up connection):


# service iptables stop
# iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# service iptables save
# service iptables restart

Open your Windows / Linux computer networking GUI tool and point router IP to 192.168.1.254 (eth0 Linux IP). You also need to setup DNS IP such as 10.0.0.21 and 10.0.0.22 . You should now able to ping or browse the internet:
c:> ping 202.54.1.20
c:> ping google.com

Run crontab Every 50 Minutes !!!

Q. How do I run a cron job or a shell script every 10 minutes using Linux / UNIX cron service?

A. cron is a time-based scheduling service in Linux / Unix-like computer operating systems.

Login to your linux system

Type the following command to enter cronjob:
$ crontab -e


Each cronjob has following syntax:

# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
* * * * * command to be executed

To get crontab to run a task every 10 minutes you could type as follow
*/50 * * * * /path/to/command
Save and close the file.

Mounting NTFS Partition on RHEL 5.x !!!!!!!

):-First of all,Setup RPMForge Repository by running this command :-

#wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-.3.6-1.el5.rf.i386.rpm

):-Install DAG’s GPG Key by executing following command

# rpm - -import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

):- To verify the package you have downloaded

# rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm

):- Install the package

# rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm

):- if you dont find packages here try some other repositories like rpmfusion, epel hope you will get it..

):- After this run yum list command if that runs completely
then Intall gcc packages from your RHEL CD/DVD or any other repository where gcc packages available.

):- GCC Packages is must for Mounting NTFS.

):- After GCC installed,run this command

# yum -y install fuse fuse-ntfs-3g dkms dkms-fuse

):- If you are running xen kernel then only run this command

# yum install kernel-xen-devel

):- If you are running PAE kernel then only run this command

# yum install kernel-PAE-devel

):- Now Make Entry in your /etc/fstab file

):- Make backup of your /etc/fstab by executing this command

# cp /etc/fstab /etc/fstab.bkp

):- Now open your /etc/fstab file in your favorite editor

# vim /etc/fstab

/dev/sda1 /mnt/ntfs ntfs-3g defaults 0 0


save & exit from file

):-Then execute this two commands in exact order

# umount -a

# mount -a

That’s it. Now You will able to see NTFS by executing df -kh or access your NTFS Volume from your mount point.

backup on Remote Host !!!!!

#!/bin/bash
# backup files in /home direscory
BACKUPSOURCE=/home/*
BACKUPDEST=/root/tmp/.
BACKUPFILE=backupnew.`date +%F`.tar.gz
COUNT=`ls -A $BACKUPDEST/backup* | wc -l`
LIMIT=2
if [ $COUNT -le $LIMIT ]
then
tar -czvf $BACKUPDEST/$BACKUPFILE $BACKUPSOURCE
scp $BACKUPDEST/$BACKUPFILE 192.168.20.13:
fi
:wq

Multimedia Player XINE ( audio/video) !!!!!

1. Download
xine-lib-0.9.13.tar.gz
xine-ui-0.9.13.tar.gz

2.Set up location
# cp xine-lib-0.9.13.tar.gz xine-ui-0.9.13.tar.gz /usr/local/src
# tar zxvf xine-lib-0.9.13.tar.gz
# tar zxvf xine-ui-0.9.13.tar.gz

3. Compile

# cd xine-lib-0.9.13
# ./configure
# make
# make install
# cd ../xine-ui-0.9.1
# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# ./configure
# make
# make install

Run video and audio...:) with XINE Player.

Recover Corrupted Partition From Bad block !!!

1) # dumpe2fs /dev/sda2 | grep superblock

2) # fsck -b 32768 /dev/sda2

3) Now try to mount file system using mount command:
# mount /dev/sda2 /mnt

4) # mount sb={alternative-superblock} /dev/device /mnt
# mount sb=32768 /dev/sda2 /mnt

5. Try to browse and access file system:
# cd /mnt
# mkdir test
# ls -l
# cp file /path/to/safe/location

Compressing PICS in Linux using command line !!!

I have stored some pictures in /tmp/images/pundir.Following example shows how I brought a 32 MB album to 7.6 MB.

root@station3:/tmp/images/pundir# ls -lh
total 32M
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00949.JPG
-rwx------ 1 root root 1.5M 2009-01-18 00:38 DSC00950.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00951.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00952.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00953.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00954.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00955.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00956.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00957.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00958.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00959.JPG
-rwx------ 1 root root 1.5M 2009-01-18 00:38 DSC00960.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00961.JPG
-rwx------ 1 root root 1.2M 2009-01-18 00:38 DSC00962.JPG
-rwx------ 1 root root 1.2M 2009-01-18 00:38 DSC00963.JPG
-rwx------ 1 root root 1.2M 2009-01-18 00:38 DSC00964.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00965.JPG
-rwx------ 1 root root 1.4M 2009-01-18 00:38 DSC00966.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00967.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00968.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00969.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00970.JPG
-rwx------ 1 root root 1.3M 2009-01-18 00:38 DSC00971.JPG
-rw-r--r-- 1 root root 1.1M 2009-01-18 00:38 DSCN3857.JPG

root@station3:/tmp/images/
pundir# mogrify -verbose *JPG -quality 60 *JPG

root@station3:/tmp/images/
pundir# ls -lh
total 7.8M
-rwx------ 1 root root 435K 2009-01-18 00:40 DSC00949.JPG
-rwx------ 1 root root 363K 2009-01-18 00:40 DSC00950.JPG
-rwx------ 1 root root 269K 2009-01-18 00:40 DSC00951.JPG
-rwx------ 1 root root 253K 2009-01-18 00:40 DSC00952.JPG
-rwx------ 1 root root 331K 2009-01-18 00:40 DSC00953.JPG
-rwx------ 1 root root 334K 2009-01-18 00:40 DSC00954.JPG
-rwx------ 1 root root 285K 2009-01-18 00:40 DSC00955.JPG
-rwx------ 1 root root 349K 2009-01-18 00:40 DSC00956.JPG
-rwx------ 1 root root 314K 2009-01-18 00:40 DSC00957.JPG
-rwx------ 1 root root 380K 2009-01-18 00:40 DSC00958.JPG
-rwx------ 1 root root 312K 2009-01-18 00:40 DSC00959.JPG
-rwx------ 1 root root 305K 2009-01-18 00:40 DSC00960.JPG
-rwx------ 1 root root 258K 2009-01-18 00:40 DSC00961.JPG
-rwx------ 1 root root 204K 2009-01-18 00:40 DSC00962.JPG
-rwx------ 1 root root 274K 2009-01-18 00:40 DSC00963.JPG
-rwx------ 1 root root 270K 2009-01-18 00:40 DSC00964.JPG
-rwx------ 1 root root 286K 2009-01-18 00:40 DSC00965.JPG
-rwx------ 1 root root 259K 2009-01-18 00:40 DSC00966.JPG
-rwx------ 1 root root 305K 2009-01-18 00:40 DSC00967.JPG
-rwx------ 1 root root 313K 2009-01-18 00:40 DSC00968.JPG
-rwx------ 1 root root 307K 2009-01-18 00:40 DSC00969.JPG
-rwx------ 1 root root 312K 2009-01-18 00:40 DSC00970.JPG
-rwx------ 1 root root 252K 2009-01-18 00:40 DSC00971.JPG
-rw-r--r-- 1 root root 874K 2009-01-18 00:40 DSCN3857.JPG
root@station3:/tmp/images/
pundir#

Alternatively we can also use:
root@station3:/tmp/images/pundir#
mogrify -verbose -resize 800x600 *JPG

Now it's time to further compress the album.
root@station3:/tmp/images/
pundir# cd .. ; tar -czvf pundir.gz pundir
pundir/
pundir/DSC00954.JPG
pundir/DSC00961.JPG
pundir/DSC00953.JPG
pundir/DSC00956.JPG
pundir/DSC00949.JPG
pundir/DSC00958.JPG
pundir/DSC00965.JPG
pundir/DSC00962.JPG
pundir/DSC00969.JPG
pundir/DSC00963.JPG
pundir/DSC00967.JPG
pundir/DSC00951.JPG
pundir/DSC00952.JPG
pundir/DSC00970.JPG
pundir/DSC00964.JPG
pundir/DSC00968.JPG
pundir/DSC00971.JPG
pundir/DSC00950.JPG
pundir/DSC00955.JPG
pundir/DSC00966.JPG
pundir/DSC00960.JPG
pundir/DSC00957.JPG
pundir/DSCN3857.JPG
pundir/DSC00959.JPG

root@station3:/tmp/pundir# ls -lh
total
7.6M
drwxr-xr-x 2 root root 4.0K 2009-01-18 00:24 pundir
-rw-r--r-- 1 root root
7.6M 2009-01-18 00:45 pundir.tar.gz
root@station3:/tmp/pundir#

Alternatively you can also convert all the pics into pdf as shown below:
root@station3:/tmp/pundir#
convert -verbose *JPG all_in_one.pdf

How to enable "password-less" login for ssh between 2 Linux machines ?

1. Generate a dsa or rsa public & private keys:

#ssh-keygent -t dsa
or
#ssh-keygen -t rsa

2. Copy the public key and complete the required formalities on the remote machine:

#ssh-copy-id -i ~/.ssh/id_dsa.pub user@IP-address

3. If all goes well you have successfully enabled password-less communication with the remote machine. Test it using "ssh"
#ssh IP-address

How to compile program under Linux


Q. I've downloaded tar ball software but I don't know how to compile the same? Can you provide the instructions for compiling a program?

A. Many new users find it difficult to compiling programs in Linux. Usually following steps are involved:

a] Download tar ball using wget

b] Untar tar ball using tar command

c] Compile program using make or configure command

d] Install software

Task: compiling program

Step # 1: Download program tar ball:
$ wget http://url-com/prog.tar.gz


Step # 2: Untar tar ball :
$ tar -zxvf prog.tar.gz
$ cd prog


Step # 3: Untar tar ball:
Configure program:
$ ./configure
Compile program:
$ make
Install program (must be run as the root, login using su or use sudo):
$ sudo make install
or
$ su -
$ make install

How to extract tar.gz File ?

Q. How do I extract tar.gz file under Linux / UNIX like operating systems?

A. tar.gz is nothing but compressed tar archive.

The tar program provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use Tar on previously created archives to extract files, to store additional files, or to update or list files which were already stored.

Initially, tar archives were used to store files conveniently on magnetic tape. The name "Tar" comes from this use; it stands for tape archiver. Despite the utility's name, Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives).

Extract tr.gz. file

To extract one or more members from an archive, enter:
tar -zxvf {file.tar.gz}
If your tarball name is backup.tar.gz, enter the following at a shell prompt:
tar -zxvf backup.tar.gz

Extracting an Entire Archive

To extract an entire archive, specify the archive file name only, with no individual file names as arguments.
tar -zxvf backup.tar.gz

How to disable loading of USB Storage Devices ?



In our practice lab i wanna disable all USB devices connected to our Red Hat Linux based workstations. I'd like to disable USB flash or hard drives, which users can use with physical access to a system to quickly copy sensitive data from it. How do I disable USB device support under RHEL 5.x workstation operating systems?

The USB storage drive automatically detects USB flash or hard drives. You can easily force and disable USB storage devices under any Linux distribution. The modprobe program used for automatic kernel module loading and can be configured to not load the USB storage driver upon demand. This will prevent the modprobe program from loading the usb-storage module, but will not prevent root (or another program) from using the insmod program to load the module manually.

Type the following command:
# echo 'install usb-storage : ' >> /etc/modprobe.conf

You can also remove USB Storage driver, enter:
# ls /lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko
# mv /lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko /root

BIOS option

You can also disable USB from system BIOS configuration option. Make sure BIOS is password protected.

How to disable Caps Lock Key in Linux ?

Q. How do I deactivate caps lock key in Linux permanently?

A. One of my friend was failed in redhat exam because he didn't give the right password in first round bcoz he didn't notice that the caps lock was active.so that i m telling you,how can you deactive caps locks on your linux machine.

You need to use the xmodmap command. It is used to edit and display the keyboard modifier map and keymap table that are used by client applications to convert event keycodes into keysyms. It is usually run from the user’s session startup script to configure the keyboard according to personal tastes.

You can also use the setxkbmap command, which maps the keyboard to use the layout determined by the options specified on the command line.

xmodmap command to turn off caps key

To turn off caps lock key, enter:
$ xmodmap -e "remove lock = Caps_Lock"
Now caps key is disabled. To enable caps key, enter:
$ xmodmap -e "add lock = Caps_Lock"
Add following code to your shell startup file ~/.bash_profile or ~/.profile file:
$ echo 'xmodmap -e "remove lock = Caps_Lock"' >> ~/.bash_profile

setxkbmap command to turn off caps locks key

To turn off caps lock key, enter:
$ setxkbmap -option ctrl:nocaps
To reset caps lock. enter:
$ setxkbmap -option

How to Block zip or pdf files in Postfix ?

Block zip or pdf files attachments under Postfix Mail

Use mime_header_checks postfix config directive

Login as the root, enter:

# vi /etc/postfix/main.cf

mime_header_checks = regexp:/etc/postfix/block_attachments

:wq!


Open /etc/postfix/block_attachments file and append code as follows:

# vi /etc/postfix/block_attachment

/name=[^>]*\.(pdf|zip)/ REJECT

:wq!


Restart the postfix services.

How to check who owns which port ?

Linux contains a lot of command line tools which make the job of a network administrator easier. One of them is netstat. Netstat is a multi-purpose network information tool. Using netstat, you can find which port is used by which process or user by using the following command:


# netstat -an | more

example : let say i would like to verify that, how own the telnet port

# netstat -nap | grep :23


There is a utility/command and called 'fuser' which also tells you which user and process owns a port

# fuser -v -n tcp 23

How to free a lot of memory and drop caches ?

Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache…

To use /proc/sys/vm/drop_caches, just echo a number to it.

To free pagecache:

# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

# echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the user should run “sync” command first!

How to crack user password (John the Ripper) ?

John the Ripper (http://openwall.com)

Download john source (tar.gz)

# tar –xvzf john…..tar.gz

# cd john.1.6/src

# make (list in src directory)

# cd ../ run

# ./john –users:, /etc/shadow (this is the process to get password)
o/p will be cracked password

# ./john –show –users: /etc/shadow ( john.port having password of user which we cracked)

How do I force users to change their passwords ?

1) Firstly, lock the account to prevent the user from using the login until the change has been made:

# usermod -L

2) Change the password expiration date to 0 to ensure the user changes the password during the next login:

# chage -d 0

3) To unlock the account after the change do the following:

# usermod -U

How to set GRUB password ?

Login as root user

Enter grub mode:

# grub

Use md5crypt to encrypt password:

grub> md5crypt
Password: ******
Encrypted: $1$jxcdN0$hVHViq1aiPf8FziuGJGZp0

Copy down encrypted password:
$1$jxcdN0$hVHViq1aiPf8FziuGJGZp0

Exit grub mode:
grub> quit

Modify file /etc/grub.conf:

# vi /etc/grub.conf

Insert encrypted password in between "splashimage..." and "title...":
...
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
password --md5 $1$jxcdN0$hVHViq1aiPf8FziuGJGZp0
title BIZ DESK (2.4.20-8elx)

Save edited file

How to Change the Timezone in Linux ?

1) Logged in as root, check which timezone your machine is currently using by executing `date`. You'll see something like Mon 17 Jan 2005 12:15:08 PM PST, PST in this case is the current timezone.

2) Change to the directory /usr/share/zoneinfo here you will find a list of time zone regions. Choose the most appropriate region, if you live in Canada or the US this directory is the "America" directory.

3) If you wish, backup the previous timezone configuration by copying it to a different location. Such as
mv /etc/localtime /etc/localtime-old

4) Create a symbolic link from the appropiate timezone to /etc/localtime. Example:
ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

5) If you have the utility rdate, update the current system time by executing
/usr/bin/rdate -s time-a.nist.gov

6) Set the ZONE entry in the file /etc/sysconfig/clock file (e.g. "America/Los_Angeles")

7) Set the hardware clock by executing:
/sbin/hwclock --systohc