普通にインストールしていても、不要なパッケージが含まれていたりするので、そういうモノを削除します。
最も、ハードウェアによって状況が異なるのでそこはそこで調整する事。
まずは、リモートからputtyを使ってrootでログイン。
login as: root root@xxx.xxx.xxx.xxx's password: (表示されないけれどパスワード) [root@sixwish ~]#
不要と思われるパッケージを削除します。
[root@sixwish ~]# rpm -ev atmel-firmware b43-openfwwf dhclient [root@sixwish ~]#
上記コマンドで、まとめて不要なパッケージを削除します。
消したのは、DHCPのクライアントとか、無線関係などです。
それ以外にも消して構わないものもあるのですが、個人的に使っているものなので、残してあります。
[root@sixwish ~]# chkconfig --list auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off cgconfig 0:off 1:off 2:on 3:on 4:on 5:on 6:off cgred 0:off 1:off 2:off 3:off 4:off 5:off 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off dnsmasq 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 iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off iscsid 0:off 1:off 2:off 3:on 4:on 5:on 6:off libvirt-guests 0:off 1:off 2:off 3:on 4:on 5:on 6:off libvirtd 0:off 1:off 2:off 3:on 4:on 5:on 6:off lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 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 postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcbind 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 rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off [root@sixwish ~]# chkconfig netfs off [root@sixwish ~]# chkconfig nfs off [root@sixwish ~]# chkconfig nfslock off [root@sixwish ~]# chkconfig postfix off [root@sixwish ~]# chkconfig rdisc off [root@sixwish ~]# chkconfig rpcbind off [root@sixwish ~]# chkconfig rpcgssd off [root@sixwish ~]# chkconfig rpcidmapd off [root@sixwish ~]# chkconfig rpcsvcgssd off [root@sixwish ~]# chkconfig --list auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off cgconfig 0:off 1:off 2:on 3:on 4:on 5:on 6:off cgred 0:off 1:off 2:off 3:off 4:off 5:off 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off dnsmasq 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 iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off iscsid 0:off 1:off 2:off 3:on 4:on 5:on 6:off libvirt-guests 0:off 1:off 2:off 3:on 4:on 5:on 6:off libvirtd 0:off 1:off 2:off 3:on 4:on 5:on 6:off lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off netfs 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:off 4:off 5:off 6:off postfix 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 restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcbind 0:off 1:off 2:off 3:off 4:off 5:off 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 rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off [root@sixwish ~]#
さて、上からなにを止めたかというと……
となります。
インストール直後ですが、特に設定することもないので、初回アップデートをかけます。
それなりにセキュリティアップデートなども含まれているはずなので、初回インストール後には必ず実行することをお奨めします。
運用に入ってからは、試験してから本番もアップデートするほうがいいです。
パッケージングに失敗して、confが飛ぶというバグが含まれていたこともありますので……
Linux版のWindowsUpdateみたいなモノ。とか書くと怒られそうですが、そんなような物だと思っておけば問題は少ないのかも。
正確には、rpm系ディストリビューションで採用されているパッケージ管理ツールの1つです。
[root@sixwish ~]# yum update Loaded plugins: fastestmirror Setting up Update Process Resolving Dependencies 中略 Total download size: XX M Is this ok [y/N]: y Downloading Packages: 中略 warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY Importing GPG key 0xC105B9DE "CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 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.example.jp [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.example.jp.rsa.key [rokubou@sixwish .ssh]$ ls authorized_keys rokubou.sixwish.example.jp.rsa.key [rokubou@sixwish .ssh]$ cat rokubou.sixwish.example.jp.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 hh:ii:ss.000000000 +0900 --- /etc/ssh/sshd_config YYYY-mm-dd hh:ii:ss.000000000 +0900 *************** *** 38,51 **** # Authentication: ! #LoginGraceTime 2m ! #PermitRootLogin yes #StrictModes yes ! #MaxAuthTries 6 #MaxSessions 10 ! #RSAAuthentication yes ! #PubkeyAuthentication yes #AuthorizedKeysFile .ssh/authorized_keys #AuthorizedKeysCommand none #AuthorizedKeysCommandRunAs nobody --- 38,51 ---- # Authentication: ! LoginGraceTime 1m ! PermitRootLogin no #StrictModes yes ! MaxAuthTries 3 #MaxSessions 10 ! RSAAuthentication yes ! PubkeyAuthentication yes #AuthorizedKeysFile .ssh/authorized_keys #AuthorizedKeysCommand none #AuthorizedKeysCommandRunAs nobody *************** *** 63,69 **** # 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 --- 63,69 ---- # 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 *************** *** 104,111 **** #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no ! #X11Forwarding no ! X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes --- 104,111 ---- #AllowAgentForwarding yes #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 hh:ii:ss.000000000 +0900 --- /etc/pam.d/su YYYY-mm-dd hh:ii:ss.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 Loaded plugins: fastestmirror Determining fastest mirrors 中略 Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: ntp i686 4.2.4p8-2.el6 base 437 k Installing for dependencies: ntpdate i686 4.2.4p8-2.el6 base 57 k Transaction Summary ================================================================================ Install 2 Package(s) Upgrade 0 Package(s) Total download size: 494 k Installed size: 1.2 M Downloading Packages: (1/2): ntp-4.2.4p8-2.el6.i686.rpm | 437 kB 00:00 (2/2): ntpdate-4.2.4p8-2.el6.i686.rpm | 57 kB 00:00 -------------------------------------------------------------------------------- Total 2.3 MB/s | 494 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : ntpdate-4.2.4p8-2.el6.i686 1/2 Installing : ntp-4.2.4p8-2.el6.i686 2/2 Installed: ntp.i686 0:4.2.4p8-2.el6 Dependency Installed: ntpdate.i686 0:4.2.4p8-2.el6 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 hh:ii:ss.000000000 +0900 --- /etc/ntp.conf YYYY-mm-dd hh:ii:ss.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 21 64 1 3.370 -10.503 0.000 ntp2.jst.mfeed. xxx.xxx.xxx.xxx 2 u 20 64 1 3.134 -8.447 0.000 ntp3.jst.mfeed. xxx.xxx.xxx.xxx 2 u 19 64 1 3.275 -7.093 0.000 [root@sixwish root]#
とりあえず、ここまでで最小構成化が完了となります。