- Create a .htpasswd file:
$ htpasswd -c .htpasswd <username> password:
- Create or add these lines to .htaccess file:
- To protect a directory:
AuthUserFile /full/path/to/.htpasswd AuthType Basic AuthName "Protected Folder" Require valid-user
- To protect a file:
AuthUserFile /full/path/to/.htpasswd AuthType Basic AuthName "Protected Page" <Files "protected_page.html"> Require valid-user </Files>
- To protect a directory:
Tuesday, November 15, 2011
How to protect a web page with htaccess with a password
Sunday, November 13, 2011
Linux Yum commands
Display available updates for installed software
Check for and update a package
Search a package or list all
Install a package
Remove/Uninstall a package
Install/Update group packages
List packages that are not official RHN
Find out which package is a file from
$ yum list updatesApply updates
$ yum updateList installed packages
$ yum list installed <package-name> # e.g. $ yum list installed httpdOR
$ rpm -qa | grep httpd*
Check for and update a package
$ yum update <package-name>
Search a package or list all
$ yum list <package-name/regex/wildcard> $ yum list all # list group packages $ yum grouplist
Install a package
$ yum install <package-name>
Remove/Uninstall a package
$ yum remove <package-name>
Install/Update group packages
$ yum groupinstall "Development Tools" $ yum groupupdate "Development Tools"
List packages that are not official RHN
$ yum list extras
Find out which package is a file from
$ yum whatprovides <filename>
Wednesday, October 26, 2011
Set up shared directory in Linux
Here is how to set up a shared directory or project among linux users. The scenario is:
First, log in as super user, create the projects directory.
Second, create a shared group.
Set up directory for group sharing.
Add users to group as supplementary group.
You can also use this command to set the primary group for a user
- The name of the shared directory: /home/projects
- The shared group name: developers
- Users: john, joe, and jane
First, log in as super user, create the projects directory.
$ mkdir /home/projects
Second, create a shared group.
$ groupadd developers
Set up directory for group sharing.
# Change group on the directory $ chgrp developers /home/projects # Set full permission for group on the directory $ chmod -R 775 /home/projects # Set SGID bit on the directory so that new files under this directory will inherit the directory's group instead of the user's (creator) group. $ chmod -R g+s /home/projects # OR combine the last two commands into one $ chmod -R 2775 /home/projects # Set umask on the directory so that the 'group write' permission will be inherited on new files and directories $ umask 002
Add users to group as supplementary group.
$ useradd -G developers john $ useradd -G developers joe $ useradd -G developers jane # Check their groups $ id john # Add a user to multiple supplementary groups (with no space after commas): $ useradd -G wheel,ftp,www,developers john # Add existing user to an existing group $ usermod -a -G wheel # Change user's primary group $ usermod -g developers john
You can also use this command to set the primary group for a user
$ useradd -g developers john
Saturday, October 1, 2011
htaccess Directory Listing Configurations
To prevent people from browsing your directoy, put this in your .htaccess file.
To allow people to see everything in your directory:
To allow people to see everything except image files:
Option -indexesOR:
IndexIgnore *
To allow people to see everything in your directory:
Option +indexes
To allow people to see everything except image files:
IndexIgnore *.gif *.jpg
How to Merge Tables
This is an example of how to insert all the missing rows from one table, tbl_backup, into another table, tbl_target. Since the primary_key is auto incremented, we will use col2 and col3 to identify unique rows.
INSERT IGNORE INTO `tbl_target` SELECT * FROM `tbl_backup` AS bkup WHERE ROW(bkup.col1, bkup.col2) NOT IN (SELECT orig.col1, orig.col2 FROM `tbl_target` AS orig);
Labels:
MySQL
Monday, April 11, 2011
Replace local home directory with an existing partition
Find the UUID of the partition:
Edit /etc/fstab file:
Move home to old-home, then remount partition.
$ blkid /dev/sda1... or ...
$ ls -l /dev/disk/by-uuid
Edit /etc/fstab file:
UUID=xxxxxxxxx /home ext3 defaults,noexec,nosuid 1 2
Move home to old-home, then remount partition.
$ mv /home /old-home $ mkdir /home $ mount -o remount /home
Labels:
Linux
Friday, March 25, 2011
Find and delete large files
Find files larger than 1GB (display filesize and lsat modified time):
Sorted by file size (human readable size):
Find files that are larger than 1GB and older than 5 days (sorted by time):
Find and delete files older than 5 days and larger than 1GB:
$ find <directory> -type f -size +1G
$ find <directory> -type f -size +1G -exec du -h --time {} \;
Sorted by file size (human readable size):
$ find <directory> -type f -size +1G -exec du --time {} \; | sort -n
$ find <directory> -type f -size +1G -exec du -h --time {} \; | sort -h
Find files that are larger than 1GB and older than 5 days (sorted by time):
$ find <directory> -type f -size +1G -mtime +5
$ find <directory> -type f -size +1G -mtime +5 -exec ls -lht {} +;
Find and delete files older than 5 days and larger than 1GB:
$ find <directory> -type f -size +1G -mtime +5 -exec rm {} \;
Friday, February 11, 2011
How to find out CentOS's version
$ cat /etc/issue CentOS release 5.7 (Final) Kernel \r on an \m $ cat /etc/centos-release CentOS release 6.3 (Final) $ uname -a Linux cle-dev 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012 x86_64 x86_64 x86_64 GNU/Linux $ rpm -qa | grep ^centos centos-release-notes-5.7-0 centos-release-5-7.el5.centos $ yum list installed |grep ^centos centos-indexhtml.noarch centos-release.x86_64 6-3.el6.centos.9 @anaconda-CentOS-201207061011.x86_64/6.3 # Find out what package were installed with 'yum' $ yum list installed # e.g. mysql-server $ yum list installed |grep ^mysql-server mysql-server.x86_64 5.1.61-4.el6 @base # e.g. php modules $ yum list installed |grep ^php php.x86_64 5.3.3-14.el6_3 @updates php-cli.x86_64 5.3.3-14.el6_3 @updates php-common.x86_64 5.3.3-14.el6_3 @updates php-gd.x86_64 5.3.3-14.el6_3 @updates php-intl.x86_64 5.3.3-14.el6_3 @updates php-mbstring.x86_64 5.3.3-14.el6_3 @updates php-mysql.x86_64 5.3.3-14.el6_3 @updates php-pdo.x86_64 5.3.3-14.el6_3 @updates php-soap.x86_64 5.3.3-14.el6_3 @updates php-xml.x86_64 5.3.3-14.el6_3 @updates php-xmlrpc.x86_64 5.3.3-14.el6_3 @updates
Subscribe to:
Posts (Atom)