PNG8とPNG24を見分けるコマンド

fileコマンドを使う。RGBAかcolormapかで判定。

# PNG24
$ file png24.png
png24.png: PNG image data, 176 x 243, 8-bit/color RGBA, non-interlaced

# PNG8 (インデックスカラー
$ file png8.png
png8.png: PNG image data, 176 x 243, 8-bit colormap, non-interlaced

# PNG8(Fireworksでアルファチャンネル追加)
$ file png8fw.png
png8fw.png: PNG image data, 176 x 243, 8-bit colormap, non-interlaced

VirtualBoxにCentOSをインストールしてSSHできるようにするまで

VirtualBoxインスタンス作成

今回はCentOS6.2-minimalをインストール。
VirtualBoxのプリセットはRedHat32。Otherだとインストール失敗した。

ネットに繋ぐ。

/etc/sysconfig/network-scripts/ifcfg-eth0 を編集、ネットワークカードの設定として以下を追加。

ONBOOT="yes" #起動時に有効
BOOTPROTO="dhcp" #DHCPIPアドレス取得

Apache インストール。

yum -y install httpd

VirtualBoxからインターネットにつながらない場合(hostをresolve出来ない)、IPv6を無効にしてみる。
http://plaza.rakuten.co.jp/punpunchan2/diary/201001050000/
ついでにMac側のIPV6も無効にする。
http://support.apple.com/kb/HT4667?viewlocale=ja_JP&locale=ja_JP
一応再起動してみる。

SSH設定

sshd_config を編集して sshd を起動。
http://tech.hitsug.net/?CentOS%2FSSH%E3%82%B5%E3%83%BC%E3%83%90

/etc/rc.d/init.d/sshd restart

ホストからSSHで繋げるようにする。
VirtualBoxNATとホストオンリーアダプタを付ける方法ポートフォワードさせる方法がある模様。今回は前者。
要はホストオンリーの方のifcfg-ethXのBOOTPROTOをstaticに変える。あとiptablesを編集。

Macのターミナルからstaticで設定したIPにSSH。ようやくつながった。

.htaccessでBasic認証

対象のディレクトリに.htaccessファイルを設置

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
AuthUserFile /path/from/root/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
#全てのユーザを許可
#require valid-user 
#htpasswdの中の特定のユーザのみ許可
require user guest
order deny,allow

AuthUserFileの場所に.htpasswdを設置。
以下のコマンドでユーザを追加できる。

$ htpasswd .htpasswd user password