JS

2013년 6월 1일 토요일

Linux Commands

Advanced Bash-Scripting Guide에 Linux commands를 정리해둔 챕터가 있다. 다음 명령에 대해 정리되어 있다. 참고로 굵은 글씨는 필자가 마음대로 표시한 것으로 원본과는 무관하다.

. (See also source) ac adduser agetty agrep ar arch at autoload awk (See also Using awk for math operations) badblocks banner basename batch bc bg bind bison builtin bzgrep bzip2 cal caller cat cd chattr chfn chgrp chkconfig chmod chown chroot cksum clear clock cmp col colrm column comm command compgen complete compress coproc cp cpio cron crypt csplit cu cut date dc dd debugfs declare depmod df dialog diff diff3 diffstat dig dirname dirs disown dmesg doexec dos2unix du dump dumpe2fs e2fsck echo egrep enable enscript env eqn eval exec exit (Related topic: exit status) expand export expr factor false fdformat fdisk fg fgrep file find finger flex flock fmt fold free fsck ftp fuser getfacl getopt getopts gettext getty gnome-mount grep groff groupmod groups (Related topic: the $GROUPS variable) gs gzip halt hash hdparm head help hexdump host hostid hostname (Related topic: the $HOSTNAME variable) hwclock iconv id (Related topic: the $UID variable) ifconfig info infocmp init insmod install ip ipcalc iptables iwconfig jobs join jot kill killall last lastcomm lastlog ldd less let lex lid ln locate lockfile logger logname logout logrotate look losetup lp ls lsdev lsmod lsof lspci lsusb ltrace lynx lzcat lzma m4 mail mailstats mailto make MAKEDEV man mapfile mcookie md5sum merge mesg mimencode mkbootdisk mkdir mke2fs mkfifo mkisofs mknod mkswap mktemp mmencode modinfo modprobe more mount msgfmt mv nc netconfig netstat newgrp nice nl nm nmap nohup nslookup objdump od openssl passwd paste patch (Related topic: diff) pathchk pax pgrep pidof ping pkill popd pr printenv printf procinfo ps pstree ptx pushd pwd (Related topic: the $PWD variable) quota rcp rdev rdist read readelf readlink readonly reboot recode renice reset resize restore rev rlogin rm rmdir rmmod route rpm rpm2cpio rsh rsync runlevel run-parts rx rz sar scp script sdiff sed seq service set setfacl setquota setserial setterm sha1sum shar shopt shred shutdown size skill sleep slocate snice sort source sox split sq ssh stat strace strings strip stty su sudo sum suspend swapoff swapon sx sync sz tac tail tar tbl tcpdump tee telinit telnet tex texexec time times tmpwatch top touch tput tr traceroute true tset tsort tty tune2fs type typeset ulimit umask umount uname unarc unarj uncompress unexpand uniq units unlzma unrar unset unsq unzip uptime usbmodules useradd userdel usermod users usleep uucp uudecode uuencode uux vacation vdir vmstat vrfy w wait wall watch wc wget whatis whereis which who whoami whois write xargs yacc yes zcat zdiff zdump zegrep zfgrep zgrep zip


  1. http://tldp.org/LDP/abs/html/part4.html

Apache HTTP Server Configuration

필요한 모듈들을 추가해야 한다. /etc/apache2/mods-enabled에서 /etc/apache2/mods-available로 심볼릭 링크를 거는 형태로 모듈을 추가한다. 설치시 기본으로 추가된 모듈 이외에 ssl, rewrite, userdir, php5 등 필요한 모듈이 있으면 잘 추가해준다.

AllowOverride의 경우 필요한 것을 잘 추가해준다.
FileInfo AuthConfig Limit

그리고 Options의 경우 Indexes가 기본으로 들어있는데 꼭 필요한 것이 아니라면 Indexes는 빼버린다. SymLinksIfOwnerMatch를 사용하여 심볼릭 링크가 아무데나 안 가도록 하는 옵션도 생각해볼 수 있다. 혹시 심볼릭 링크의 owner가 chown으로 안 바뀌어서 고민이라면 chown -h를 사용하면 된다.
Options FollowSymLinks MultiViews SymLinksIfOwnerMatch

그리고 ScriptAlias를 사용하지 않는다면 주석 처리해도 좋다.

SSL을 사용하기 위해 /etc/apache2/sites-availabe/default-ssl을 /etc/apache2/sites-enabled/에서 심볼릭 링크로 연결한다. 그리고 인증서 설정을 적절히 해준다.
SSLCertificateFile    /etc/ssl/certs/my2048.cer
SSLCertificateKeyFile /etc/ssl/private/my2048.key

SSLCertificateChainFile /etc/ssl/certs/chain.cer

SSLCACertificateFile /etc/ssl/certs/CA.cer

인증서 passphrase를 자동으로 입력하기 위해 /etc/apache2/mods-enabled/ssl.conf를 변경한다. 여기서 mypass.sh는 암호를 echo하는 스크립트이다.
SSLPassPhraseDialog  exec:/etc/ssl/private/mypass.sh

보통의 http 접속이 https로 접속되도록 rewrite condition도 설정해준다. 일부 페이지만 https를 강제하고 싶다면 rewrite를 써서 해결할 수 있다. Rewrite rule은 ? 뒤에 붙은 것을 기본적으로 무시하므로 %{QUERY_STRING}을 써야할 수도 있다. 그리고 QSA는 query string이 rewrite 이후에도 남아있게 만드는 옵션이다.
#### RewriteEngine related code
RewriteEngine on

# login pages
RewriteCond %{HTTPS} !=on
RewriteCond %{QUERY_STRING} do=login
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

# internal pages
RewriteCond %{HTTPS} !=on
RewriteRule ^/my_internal/.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

혹시 모든 접속을 https로 보내는 것을 원한다면 redirect를 쓰면 된다.
ServerName www.example.com
Redirect / https://www.example.com/


더 필요한 것이 있으면 잘 해주면 된다.

Procmail Configuration

postfix나 dovecot도 전체 기능 중 일부만 이해하고 있지만, procmail은 특히 심하다. 필자는 procmail의 설정에 대해서는 잘 모르고 있다.

가장 중요한 것은 디렉토리를 정하는 것이다. 설정 파일 /etc/procmailrc에 다음과 같이 적으면 된다. 그리고 privileges를 박탈하는 것도 좋은 옵션이다. 참고로 아래 설정 파일은 자체 검증을 거치지 않았다.
DROPPRIVS=yes
DEFAULT="$HOME/Maildir/"   
MAILDIR="$HOME/Maildir/"

Dovecot Configuration

Dovecot version 2.x를 기준으로 작성하였다. 기본 기능만 사용하는 경우 어쩌면 version 1.x가 더 설정하기 쉬웠던 것 같다. 하지만 2.x도 wiki를 잘 보면 설정하기 쉬운 편이다.

가장 중요한 설정은 mail_location이다. /etc/dovecpt/10-mail.conf에서 변경해준다.
mail_location = maildir:~/Maildir

SSL 또는 TLS를 사용하기 위해 /etc/dovecot/10-ssl.conf에서 ssl = yes로 바꾸고, 인증서 설정도 잘 해준다. 혹시 인증서를 만들어야 할 경우 2048비트 이상의 인증서를 권장한다. 참고로 2048비트 인증서는 아마도 2030년 정도까지 사용할 수 있을 것으로 예상하고 있다고 한다.
ssl = yes

SASL을 위해 /etc/dovecot/10-main.conf를 다음과 같이 변경한다. MTA는 postfix를 쓴다고 가정하였다.
service auth {
  #...
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    # Assuming the default Postfix user and group
    user = postfix
    group = postfix        
  }
  #...
}

  1. http://wiki2.dovecot.org/
  2. http://wiki2.dovecot.org/SSL
  3. http://wiki2.dovecot.org/HowTo/PostfixAndDovecotSASL