dselect
を行い、[I]nstall の前に不要だが選択されている パッケージを削除しましょう。本当に最小限のソフトウェアだけをサーバに 残しましょう。
$ ps aux $ netstat -pn -l -A inet # /usr/sbin/lsof -i | grep LISTEN3 番目のコマンドがうまくいくためには lsof-2.2 をインストール する必要があるでしょう (root として実行してください)。lsof は LISTEN という 単語をあなたのロケールの設定にあわせて翻訳するかもしれないことに注意する べきです。
lsof
and dpkg
, does just that:
#!/bin/sh # FIXME: this is quick and dirty; replace with a more robust script snippet for i in `sudo lsof -i | grep LISTEN | cut -d " " -f 1 |sort -u` ; do pack=`dpkg -S $i |grep bin |cut -f 1 -d : | uniq` echo "Service $i is installed by $pack"; init=`dpkg -L $pack |grep init.d/ ` if [ ! -z "$init" ]; then echo "and is run by $init" fi done
dpkg --purge
), or disable the service from starting automatically at boot time using update-rc.d
(see 「デーモンサービスを停止する」).
/etc/inetd.conf
using:
$ grep -v "^#" /etc/inetd.conf | sort -uThen disable those services that are not needed by commenting out the line that includes them in
/etc/inetd.conf
, removing the package, or using update-inetd
.
/usr/sbin/tcpd
を使うもの) が あれば、/etc/hosts.allow
と /etc/hosts.deny
が あなたのサービスポリシーにしたがって設定されていることを確かめましょう。
# init 1 (....) # init 2
# for i in `/usr/sbin/lsof -i |grep LISTEN |cut -d " " -f 1 |sort -u`; \ > do user=`ps ef |grep $i |grep -v grep |cut -f 1 -d " "` ; \ > echo "Service $i is running as user $user"; doneConsider changing these services to a specific user/group and maybe
chroot
'ing them for increased security. You can do this by changing the /etc/init.d
scripts which start the service. Most services in Debian use start-stop-daemon
, which has options (--change-uid
and --chroot
) for accomplishing this. A word of warning regarding the chroot
'ing of services: you may need to put all the files installed by the package (use dpkg -L) providing the service, as well as any packages it depends on, in the chroot
'ed environment. Information about setting up a chroot
environment for the ssh
program can be found in 「Chroot environment for SSH」.