普通にインストールしていても、不要なパッケージが含まれていたりするので、そういうモノを削除する。
最も、ハードウェアによって状況が異なるのでそこはそこで調整する事。
まずは、リモートからputtyを使ってrootでログイン。
login as: root root@172.16.2.70's password: (表示されないけれどパスワード) Last login: Sat Jul 12 13:41:16 2008 [root@fivestar-dom0 ~]#
不要と思われるパッケージを削除します。
[root@sixwish ~]# rpm -ev anthy kasumi scim-anthy \ dhcdbd dhclient dhcpv6_client \ wvdial isdn4k-utils rp-pppoe irda-utils NetworkManager \ bluez-gnome bluez-libs bluez-utils \ ipsec-tools wpa_supplicant yp-tools ypbind firstboot-tui \ system-config-network-tui system-config-securitylevel-tui \ nscd nss_ldap dos2unix [root@sixwish ~]#
上記コマンドで、まとめて不要なパッケージを削除します。
消したのは、DHCPのクライアントとか、無線関係、Bluetooh関係、ypモジュール、system-config関係と初回ブート時のスクリプト、IMEなどです。
それ以外にも消して構わないものもあるのですが、個人的に使っているものなので、残してあります。
[root@sixwish ~]# chkconfig --list acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off apmd 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off avahi-daemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off avahi-dnsconfd 0:off 1:off 2:off 3:off 4:off 5:off 6:off conman 0:off 1:off 2:off 3:off 4:off 5:off 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off gpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off ibmasm 0:off 1:off 2:off 3:off 4:off 5:off 6:off ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:on 3:on 4:on 5:on 6:off kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off mcstrans 0:off 1:off 2:on 3:on 4:on 5:on 6:off mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off mdmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off messagebus 0:off 1:off 2:off 3:on 4:on 5:on 6:off microcode_ctl 0:off 1:off 2:on 3:on 4:on 5:on 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off netplugd 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off oddjobd 0:off 1:off 2:off 3:off 4:off 5:off 6:off pcscd 0:off 1:off 2:on 3:on 4:on 5:on 6:off portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off readahead_later 0:off 1:off 2:off 3:off 4:off 5:on 6:off restorecond 0:off 1:off 2:on 3:on 4:on 5:on 6:off rpcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcidmapd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcsvcgssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off smartd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off xend 0:off 1:off 2:on 3:on 4:on 5:on 6:off xendomains 0:off 1:off 2:off 3:on 4:on 5:on 6:off xfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off yum-updatesd 0:off 1:off 2:off 3:on 4:on 5:on 6:off [root@sixwish ~]# chkconfig apmd off [root@sixwish ~]# chkconfig cups off [root@sixwish ~]# chkconfig gpm off [root@sixwish ~]# chkconfig mdmonitor off [root@sixwish ~]# chkconfig netfs off [root@sixwish ~]# chkconfig rdisc off [root@sixwish ~]# chkconfig rpcgssd off [root@sixwish ~]# chkconfig rpcidmapd off [root@sixwish ~]# chkconfig rpcsvcgssd off [root@sixwish ~]# chkconfig yum-updatesd off [root@sixwish ~]# chkconfig --list acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off apmd 0:off 1:off 2:off 3:off 4:off 5:off 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off avahi-daemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off avahi-dnsconfd 0:off 1:off 2:off 3:off 4:off 5:off 6:off conman 0:off 1:off 2:off 3:off 4:off 5:off 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off gpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off ibmasm 0:off 1:off 2:off 3:off 4:off 5:off 6:off ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:on 3:on 4:on 5:on 6:off kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off mcstrans 0:off 1:off 2:on 3:on 4:on 5:on 6:off mdmonitor 0:off 1:off 2:off 3:off 4:off 5:off 6:off mdmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off messagebus 0:off 1:off 2:off 3:on 4:on 5:on 6:off microcode_ctl 0:off 1:off 2:on 3:on 4:on 5:on 6:off netfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off netplugd 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off oddjobd 0:off 1:off 2:off 3:off 4:off 5:off 6:off pcscd 0:off 1:off 2:on 3:on 4:on 5:on 6:off portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off readahead_later 0:off 1:off 2:off 3:off 4:off 5:on 6:off restorecond 0:off 1:off 2:on 3:on 4:on 5:on 6:off rpcgssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcidmapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcsvcgssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off smartd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off xend 0:off 1:off 2:on 3:on 4:on 5:on 6:off xendomains 0:off 1:off 2:off 3:on 4:on 5:on 6:off xfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off yum-updatesd 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@sixwish ~]#
さて、上からなにを止めたかというと……
という感じ。
インストール直後ですが、特に設定することもないので、初回アップデートをかけます。
それなりにセキュリティアップデートなども含まれているはずなので、初回インストール後には必ず実行することをお奨め。
運用に入ってからは、試験してから本番もアップデートするほうがいいです。パッケージングに失敗して、confが飛ぶというバグが含まれていたこともありますので……
Linux版のWindowsUpdateみたいなモノ。とか書くと怒られそうですが、そんなような物だと思っておけば問題は少ないのかも。
正確には、rpm系ディストリビューションで採用されているパッケージ管理ツールの1つです。親戚関係にaptなどがあります。
[root@sixwish ~]# yum update Loading "installonlyn" plugin Setting up Update Process Setting up repositories 中略 Total download size: XX M Is this ok [y/N]: y Downloading Packages: 中略 warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897 Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-key@centos.org>" from http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 Is this ok [y/N]: y 中略 Complete! [root@sixwish ~]#
いつまでもrootユーザーでSSHログインしているわけにも行かないので、メンテナンスログインユーザーなどを追加する。
[root@sixwish ~]# useradd rokubou -c "Fuu.Rokubou" -G wheel [root@sixwish ~]#
主にメンテナンスを行うユーザーであるので、wheelグループにも追加しておく。
SSHでログインするための鍵を作成する。
[root@sixwish ~]# su - rokubou [rokubou@sixwish ~]$ ssh-keygen -t rsa -b 1024 Generating public/private rsa key pair. Enter file in which to save the key (/home/rokubou/.ssh/id_rsa):(何も入力しない) Created directory '/home/rokubou/.ssh'. Enter passphrase (empty for no passphrase):(パスワード) Enter same passphrase again:(上で入力したのと同じパスワード) Your identification has been saved in /home/rokubou/.ssh/id_rsa. Your public key has been saved in /home/rokubou/.ssh/id_rsa.pub. The key fingerprint is: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx rokubou@sixwish.dynalias.net [rokubou@sixwish ~]$ cd .ssh [rokubou@sixwish .ssh]$ ls id_rsa id_rsa.pub [rokubou@sixwish .ssh]$ mv id_rsa.pub authorized_keys [rokubou@sixwish .ssh]$ mv id_rsa rokubou.sixwish.dynalias.net.rsa.key [rokubou@sixwish .ssh]$ ls authorized_keys rokubou.sixwish.dynalias.net.rsa.key [rokubou@sixwish .ssh]$ cat rokubou.sixwish.dynalias.net.rsa.key -----BEGIN RSA PRIVATE KEY----- (省略) -----END RSA PRIVATE KEY----- [rokubou@sixwish .ssh]$
表示された公開鍵の内容をファイルに保存する。
手順は省略するが、puttyで使えるように変換する。
新しくputtyを開いて、鍵を使ってログインできるかを試みる。
Using username "rokubou". Authenticating with public key "imported-openssh-key" Passphrase for key "imported-openssh-key":(パスワード) [rokubou@sixwish ~]$ [rokubou@sixwish ~]$ logout
ログインできたら、そのまま閉じてしまう。
rootログインの制限と、ログイン方式の制限をかけます。
[rokubou@sixwish .ssh]$ logout [root@sixwish ~]$ cp /etc/ssh/sshd_config /etc/ssh/sshd_config.org [root@sixwish ~]$ vi /etc/ssh/sshd_config
*** /etc/ssh/sshd_config.org YYYY-mm-dd --:--:--.000000000 +0900 --- /etc/ssh/sshd_config YYYY-mm-dd --:--:--.000000000 +0900 *************** *** 35,47 **** # Authentication: ! #LoginGraceTime 2m ! #PermitRootLogin yes #StrictModes yes ! #MaxAuthTries 6 ! #RSAAuthentication yes ! #PubkeyAuthentication yes #AuthorizedKeysFile .ssh/authorized_keys # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts --- 35,47 ---- # Authentication: ! LoginGraceTime 1m ! PermitRootLogin no #StrictModes yes ! MaxAuthTries 3 ! RSAAuthentication yes ! PubkeyAuthentication yes #AuthorizedKeysFile .ssh/authorized_keys # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts *************** *** 57,63 **** # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no ! PasswordAuthentication yes # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes --- 57,63 ---- # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no ! PasswordAuthentication no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes *************** *** 92,99 **** AcceptEnv LC_IDENTIFICATION LC_ALL #AllowTcpForwarding yes #GatewayPorts no ! #X11Forwarding no ! X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes --- 92,99 ---- AcceptEnv LC_IDENTIFICATION LC_ALL #AllowTcpForwarding yes #GatewayPorts no ! X11Forwarding no ! #X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes
[root@sixwish ~]# /etc/rc.d/init.d/sshd restart sshdを停止中: [ OK ] sshdを起動中: [ OK ] [root@sixwish ~]#
サービス再起動後にrootでログインできない事と、鍵方式でログインできる事を確認する。
上記で、wheelグループを使うことにしているのでいるので、pamの設定を変更してrootになる事のできるユーザを制限します。
[root@sixwish ~]# cp /etc/pam.d/su /etc/pam.d/~su [root@sixwish ~]# vi /etc/pam.d/su
*** /etc/pam.d/~su YYYY-mm-dd --:--:--.000000000 +0900 --- /etc/pam.d/su YYYY-mm-dd --:--:--.000000000 +0900 *************** *** 3,9 **** # Uncomment the following line to implicitly trust users in the "wheel" group. #auth sufficient pam_wheel.so trust use_uid # Uncomment the following line to require a user to be in the "wheel" group. ! #auth required pam_wheel.so use_uid auth include system-auth account sufficient pam_succeed_if.so uid = 0 use_uid quiet account include system-auth --- 3,9 ---- # Uncomment the following line to implicitly trust users in the "wheel" group. #auth sufficient pam_wheel.so trust use_uid # Uncomment the following line to require a user to be in the "wheel" group. ! auth required pam_wheel.so use_uid auth include system-auth account sufficient pam_succeed_if.so uid = 0 use_uid quiet account include system-auth
[root@sixwish ~]#
yumを使用して、パッケージを取得、インストール。
[root@sixwish ~]# yum -y install ntp Loading "installonlyn" plugin Setting up Install Process Setting up repositories 中略 Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: ntp i386 4.2.2p1-5.el5 base 1.3 M Transaction Summary ============================================================================= Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 1.3 M Downloading Packages: (1/1): ntp-4.2.2p1-5.el5. 100% |=========================| 1.3 MB xx:xx Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: ntp ######################### [1/1] Installed: ntp.i386 0:4.2.2p1-5.el5 Complete! [root@sixwish ~]#
ntpは、GPSや原子時計を使って時刻を正確に刻んでいるntpサーバー(Stratum1)などから、ネットワーク経由で時刻情報を得て自分の時間を合わせるという仕組みを持っています。
よって、設定ではこの上位ntpのサーバーを指定したりします。
[root@sixwish ~]# cp /etc/ntp.conf /etc/ntp.conf.org [root@sixwish ~]# vi /etc/ntp.conf
*** /etc/ntp.conf.org YYYY-mm-dd --:--:--.000000000 +0900 --- /etc/ntp.conf YYYY-mm-dd --:--:--.000000000 +0900 *************** *** 14,22 **** # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). ! server 0.rhel.pool.ntp.org ! server 1.rhel.pool.ntp.org ! server 2.rhel.pool.ntp.org #broadcast 192.168.1.255 key 42 # broadcast server #broadcastclient # broadcast client --- 17,25 ---- # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). ! server ntp1.jst.mfeed.ad.jp ! server ntp2.jst.mfeed.ad.jp ! server ntp3.jst.mfeed.ad.jp #broadcast 192.168.1.255 key 42 # broadcast server #broadcastclient # broadcast client
[root@sixwish ~]#
編集後、ntpdateを使用してPCの時刻を合わせます。これをしない場合、ntpサーバーとの時間差が大きすぎてntpdが時刻あわせをしてくれない……ということもあるからです。
時刻あわせ後、サービスとして自動起動するようになるまで設定してしまいましょう。
[root@sixwish ~]# ntpdate ntp1.jst.mfeed.ad.jp dd MMM --:--:-- ntpdate[----]: step time server xxx.xxx.xxx.xxx offset ---.------ sec [root@sixwish ~]# hwclock --systohc [root@sixwish ~]# /etc/rc.d/init.d/ntpd start ntpdを起動中: [ OK ] [root@sixwish ~]# chkconfig ntpd on [root@sixwish ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== ntp1.jst.mfeed. xxx.xxx.xxx.xxx 2 u 9 64 1 7.353 -1414.6 0.001 ntp2.jst.mfeed. xxx.xxx.xxx.xxx 2 u 8 64 1 6.994 -1414.7 0.001 ntp3.jst.mfeed. xxx.xxx.xxx.xxx 2 u 7 64 1 7.031 -1414.6 0.001 LOCAL(0) LOCAL(0) 10 l 6 64 1 0.000 0.000 0.002 [root@sixwish root]#
とりあえず、ここまでで最小構成化が完了となります。