LinuxHelps.com

A blog for Linux Lovers.

Archive for May, 2009

Posted by sibu on May 24, 2009

Changing time zone linux

Change Time Zone

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 -s /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.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

How to Change Date and Time

You can change the date and time on linux machine using the date command
Eg: If you want to change the date to July 31, 11:16 pm then type as follows

date 07312316
If you want to change the year as well, you could type
“date 073123161998”

You can also use the following:

date -s “31 JULY 1998 23:16:00″

Posted by sibu on May 24, 2009

Disable SELinux for only Apache / httpd in Linux

You can disable Apache SELinux protection easily. Please keep in mind that by disabling SELinux for apache you are inviting more security related problems.

Disable Apache SELinux Protection

Open /etc/selinux/targeted/booleans file using a text editor:
# vi /etc/selinux/targeted/booleans
Append or modify value for httpd_disable_trans as follows:
httpd_disable_trans=1

Save and close the file.

Type the following two commands:
# setsebool httpd_disable_trans 1
# /etc/init.d/httpd restart

GUI tool to disable SELinux for Apache                                                                                                         Open a shell prompt
Type the command system-config-securitylevel
system-config-securitylevel &
Next select SELinux tab > click on Disable SELinux protection for httpd daemon checkbox > Save the changes
Finally restart httpd service:
# /etc/init.d/httpd restart

Posted by sibu on May 24, 2009

Flushing DNS cache

You can flush your DNS cache as per following.

1) For Windows

Start -> Run -> type cmd
- in command prompt, type ipconfig /flushdns
- Done! You Window DNS cache has just been flush.

2) For Linux

- To restart the nscd daemon, type /etc/rc.d/init.d/nscd restart in your terminal
- Once you run the command your linux DNS cache will flush.

3) For Mac OS X

- type lookupd -flushcache in your terminal to flush the DNS resolver cache.
ex: bash-2.05a$ lookupd -flushcache
- Once you run the command your DNS cache (in Mac OS X) will flush.

Posted by sibu on May 24, 2009

Required permissions and directories for Fantastico

Fantastico requires certain files and directories to have the following permissions:

NOTE: Depending on your server setup, the files may be in slightly different locations.

Files:
/bin/tar 0755
/bin/gzip 0755
/usr/bin/wget 0700
/bin/bash 0755

Directories (create if they do not exist):
/tmp 1777
/usr/local/cpanel/base/tmp 1777
/usr/local/cpanel/3rdparty/tmp 1777

Posted by sibu on May 24, 2009

Yum Commands

YUM packages updater (Fedora, RedHat and like)

yum install package_name download and install a rpm package
yum localinstall package_name.rpm That will install an RPM, and try to resolve all the dependencies for you using your repositories.
yum update update all rpm packages installed on the system
yum update package_name upgrade a rpm package
yum remove package_name remove a rpm package
yum list list all packages installed on the system
yum search package_name find a package on rpm repository
yum clean packages clean up rpm cache erasing downloaded packages
yum clean headers remove all files headers that the system uses to resolve dependency
yum clean all remove from the cache packages and headers files

Posted by sibu on May 24, 2009

RPM commands

rpm -ivh package.rpm install a rpm package
rpm -ivh –nodeps package.rpm install a rpm package ignoring dependencies requests
rpm -U package.rpm upgrade a rpm package without changing configuration files
rpm -F package.rpm upgrade a rpm package only if it is already installed
rpm -e package_name.rpm remove a rpm package
rpm -qa show all rpm packages installed on the system
rpm -qa | grep httpd show all rpm packages with the name “httpd”
rpm -qi package_name obtain information on a specific package installed
rpm -qg “System Environment/Daemons” show rpm packages of a group software
rpm -ql package_name show list of files provided by a rpm package installed
rpm -qc package_name show list of configuration files provided by a rpm package installed
rpm -q package_name –whatrequires show list of dependencies required for a rpm packet
rpm -q package_name –whatprovides show capability provided by a rpm package
rpm -q package_name –scripts show scripts started during installation / removal
rpm -q package_name –changelog show history of revisions of a rpm package
rpm -qf /etc/httpd/conf/httpd.conf verify which rpm package belongs to a given file
rpm -qp package.rpm -l show list of files provided by a rpm package not yet installed
rpm –import /media/cdrom/RPM-GPG-KEY import public-key digital signature
rpm –checksig package.rpm verify the integrity of a rpm package
rpm -qa gpg-pubkey verify integrity of all rpm packages installed
rpm -V package_name check file size, permissions, type, owner, group, MD5 checksum and last modification
rpm -Va check all rpm packages installed on the system - use with caution
rpm -Vp package.rpm verify a rpm package not yet installed
rpm2cpio package.rpm | cpio –extract –make-directories *bin* extract executable file from a rpm package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm install a package built from a rpm source
rpmbuild –rebuild package_name.src.rpm build a rpm package from a rpm source

Posted by sibu on May 24, 2009

File search commands

find  / -name file1 - search file and directory into root filesystem from ‘/’
find / -user user1 - search files and directories belonging to ‘user1′
find /home/user1 -name \*.bin - search files with ‘. bin’ extension within directory ‘/ home/user1′
find /usr/bin -type f -atime +100 - search binary files are not used in the last 100 days
find /usr/bin -type f -mtime -10 - search files created or changed within 10 days
find / -name \*.rpm -exec chmod 755 ‘{}’ \;   - search files with ‘.rpm’ extension and modify permits
find / -xdev -name \*.rpm - search files with ‘.rpm’ extension ignoring removable partitions as cdrom, pen-drive, etc.…
locate \*.ps - find files with the ‘.ps’ extension - first run ‘updatedb’ command
whereis halt -  show location of a binary file, source or man
which halt  - show full path to a binary / executable

Posted by sibu on May 24, 2009

User management commands

Users and Groups

groupadd group_name create a new group
groupdel group_name delete a group
groupmod -n new_group_name old_group_name rename a group
useradd -c “Name Surname ” -g admin -d /home/user1 -s /bin/bash user1 create a new user belongs “admin” group
useradd user1 create a new user
userdel -r user1 delete a user ( ‘-r’ eliminates home directory)
usermod -c “User FTP” -g system -d /ftp/user1 -s /bin/nologin user1 change user attributes
passwd change password
passwd user1 change a user password (only by root)
chage -E 2005-12-31 user1 set deadline for user password
pwck check correct syntax and file format of ‘/etc/passwd’ and users existence
grpck check correct syntax and file format of ‘/etc/group’ and groups existence
newgrp group_name log in to a new group to change default group of newly created files.

Posted by sibu on May 24, 2009

How to check who are logged in whm/cpanel with ip and user name details?

There are two ways you can check who is currently logged into WHM or cPanel.

1) Log in to the server via SSH and run ps aux | grep whostmgrd to see who’s currently active in WHM, and ps aux | grep cpaneld to see who’s currently active in cPanel. If the users have been idle for some time, this method may not work.

2) This method is less than ideal, but if you know the IP address then you can tail -f /usr/local/cpanel/logs/access_log | grep ip.address to see what they are doing, again only if they are active within WHM or cPanel will this work.

You can check this from the login_log in /usr/local/cpanel/logs or /usr/local/cpanel/logs/access_log.

Posted by sibu on May 24, 2009

Difference between ‘mount’ and ‘mount -a’

There is a slight difference between the commands - “mount” and “mount -a”.

1. When you type “mount”, it will display the output of the file “/etc/mtab“.

For example,

# mount
/dev/sda5 on / type ext3 (rw,usrquota)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda1 on /boot type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/sda7 on /home type ext3 (rw,usrquota)
/dev/sda8 on /tmp type ext3 (rw,noexec,nosuid)
/dev/sda3 on /usr type ext3 (rw,usrquota)
/dev/sda2 on /var type ext3 (rw,usrquota)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/tmp on /var/tmp type none (rw,noexec,nosuid,bind)

The content of the file “/etc/mtab” is:

# cat /etc/mtab
/dev/sda5 / ext3 rw,usrquota 0 0
none /proc proc rw 0 0
none /sys sysfs rw 0 0
none /dev/pts devpts rw,gid=5,mode=620 0 0
usbfs /proc/bus/usb usbfs rw 0 0
/dev/sda1 /boot ext3 rw 0 0
none /dev/shm tmpfs rw 0 0
/dev/sda7 /home ext3 rw,usrquota 0 0
/dev/sda8 /tmp ext3 rw,noexec,nosuid 0 0
/dev/sda3 /usr ext3 rw,usrquota 0 0
/dev/sda2 /var ext3 rw,usrquota 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/tmp /var/tmp none rw,noexec,nosuid,bind 0 0

2. When you type the command “mount -a”, it will take the output of the file “/etc/fstab“.

# cat /etc/fstab

# This file is edited by fstab-sync - see ‘man fstab-sync’ for details
LABEL=/ / ext3 defaults,usrquota 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
LABEL=/home /home ext3 defaults,usrquota 1 2
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/usr /usr ext3 defaults,usrquota 1 2
LABEL=/var /var ext3 defaults,usrquota 1 2
LABEL=SWAP-sda6 swap swap pri=0,defaults 0 0

Note: The file “/etc/mtab” has the entries of temporary partitions such as USB drive. But, the file “/etc/fstab” has the entries of mounted partitions in the server.