Entries tagged with “linux” from Bobby Maisnam -- Blog

To protect a folder in Unix/Linux using .htaccess and .htpasswd, use the following steps:

[1] Go to folder you wish to protect and create a file called .htaccess with the following info:

AuthUserFile /home/your_username/.htpasswd
AuthGroupFile /dev/null
AuthName "Restricted Area"
AuthType Basic

<Limit GET POST PUT>
require user admin
</Limit>

[2] Go to the location for your .htpasswd file (typically should be in your home area outside of the public_html folder). If the .htpasswd file does not exist, create it using the following syntax. Enter the password when asked for.
> cd /home/your_username/
> htpasswd -c .htpasswd admin

[3] Make sure your .htpasswd file is readable from the web - chmod it to 644.
> chmod 644 .htpasswd

[4] If additional users need to be allowed access to the same folder,
[4.1] add the users to the .htaccess file (edit the file mentioned in step 1):
require user admin user2 user3
[4.2] add the users to the .htpasswd file (update the file mentioned in step 3). Note that the "-c" option in step 3 is not used here. The "-c" is only used when creating the .htaccess file:
> htpasswd .htpasswd user2
> htpasswd .htpasswd user3


An excellent and easy tutorial is at: http://hoohoo.ncsa.uiuc.edu/docs/tutorials/user.html. A cached copy is here.

Unix/Linux commands

| | Comments (1)

12:08 PM 4/27/2005: This is my personal page for quick reference to Linux commands I generally use. I have set the date to one year back i.e. 04/27/2004 and so it should not appear in the RSS feed and annoy you! :)

- Man pages
- Unix Commands and Utilities
- Linux Basics


[1] Find a file
find . -name filename.ext
find . -name project*.* (example)


[2.1] Zip a file
gzip filename (original file is moved to filename.gz)

[2.2] Zip(tar) a directory
tar -cvf file.tar directory_name (original directory is retained)
tar -tvf file.tar (list contents)

General rule is: tar and then gzip:
tar -cvf file.tar directory_name
gzip file.tar
So, you will get a tar.gz file

[2.3] Zip(tar) a directory in 1 step
tar czvf file.tar.gz directory_name (original directory is retained)


[3] Unzip a file

[3.1] .gz file
gzip -d file.gz
(Note: original .gz file gets deleted)

[3.2] tar.gz file
gzip -d file.tar.gz
and then
tar -xvf file.tar


[4] Creating a symlink
ln -s target_path symlink_name


[5] Delete a non empty directory
\rm -fr directory_name


[6] List detailed directory listing by last modified
ls -lt


[7] Copy entire directory
mkdir target_directory
cd source_directory
cp -ap . target_directory

Other options:
cp -apv . target_directory (for verbose results)
\cp -ap . target_directory (for unix)


[8] View quota
quota -v


[9] View disk usage for current folder
du -k
du -h (uses K, M, G etc for KB, MB, GB - this is better)


[10] View space usage on disks
df -k


[11] change the file permissions of all files in a directory
chmod -R 755 docs


[12] Changing the default editor
export EDITOR=pico


[13] Edit crontab
crotab -e


[14] View uptime
uptime


[15] Restart iptables
/etc/init.d/iptables start
/etc/init.d/iptables stop
/etc/init.d/iptables restart

http://www.siliconvalleyccie.com/linux-hn/iptables-intro.htm

[16] Count number of files
find directory_name \! -type d | wc -l
Example: find /var/qmail/queue/pid \! -type d | wc -l

More at: http://www.dsl.org/cookbook/cookbook_10.html

[17] Change group
chgrp new_group filename

[18] Change owner
chown new_owner filename

[19] Find IP address
/sbin/ifconfig
Note: This gives the local ip of your machine. Look in eth0 > inet addr.

[20] Find folder size
du -sh * (this is good)
du -ah --max-depth=1
du - sc /foldername/*

[21] Start Apache
/etc/rc.d/init.d/httpd start (start)
/etc/rc.d/init.d/httpd restart (restart)
or
/sbin/service httpd start
/sbin/service httpd restart

[22] Copy entire folder from one Linux server to another using SCP
Syntax:
> scp -r source_folder user@server:destination_folder
Example:
> scp -r /home/maisnam/www maisnam@192.168.1.107:/home/maisnam/
The above example copies the www folder in /home/maisnam/ from server 1 to the /home/maisnam/ folder on server 2 (192.168.1.107 in the example above).

[22] Hard Drive Info
fdisk -l
df -h
hdparm -i device
http://www.linuxforums.org/forum/peripherals-hardware/32190-command-hard-drive-info.html
Notes: hda or sda = hard drive, sdb = secondary hard drive, sdc = thumb drive etc

[23] Linux Version
uname -a

[24] Yum GroupInstall
yum groupinstall "MySQL Server"
yum groupinstall "Web Server"
yum grouplist
http://www.cyberciti.biz/faq/rhel-yum-grouplist-groupinstall-option-not-working/

# display list of yum packages
yum list available

# install single yum package
yum install mysql

# display list of installed packages
# http://www.electrictoolbox.com/yum-list-installed-packages/
yum list installed
yum list installed | more
yum list installed | less

Feed Subscription

If you use an RSS reader, you can subscribe to a feed of all future entries tagged “linux”.

Subscribe to feed Subscribe to feed

Tags

Powered by Movable Type 4.0