環境構築 †ユーザ追加 †# useradd -m username # passwd username sudo の許可 †グループの sudo に許可するか、ユーザごとに sudo に許可するかは、好きなほうで。 1) sudo がインストールされているか確認する †# yum list installed | grep sudo sudo.i386 1.6.8p12-12.el5 installed もし、インストールされていなかった場合は、インストールする # yum install sudo 2) グループの sudo を許可する方法 †wheel ユーザの確認 †# cat /etc/group | grep wheel wheel ユーザの許可をアンコメント †# /usr/sbin/visudo 変更前 # %wheel ALL=(ALL) ALL ↓ 変更後 %wheel ALL=(ALL) ALL username (ユーザ)に wheel グループを追加 †# usermod -a -G wheel username 3) ユーザごとに sudo を許可する方法 †sudo を許可するユーザを追加する †# /usr/sbin/visudo 変更前 # Allow root to run any commands anywhere root ALL=(ALL) ALL ↓ 変更後 # Allow root to run any commands anywhere root ALL=(ALL) ALL username ALL=(ALL) ALL 4) 権限を設定する †/usr/local/src に権限を追加しておく。 # cd /usr/local/ # chgrp wheel ./src # chmod g+w ./src # chmod g+s ./src 変更前 drwxr-xr-x 2 root root 4096 Mar 30 2007 src ↓ 変更後 drwxrwsr-x 2 root wheel 4096 Mar 30 2007 src SSH の設定 †ファイルの修正 †sshd_config を以下のように設定する。 $ sudo vim /etc/ssh/sshd_config root ログインの禁止 †変更前 #PermitRootLogin yes ↓ 変更後 PermitRootLogin no SSH2でのみ接続を許可 †変更前 #Protocol 2,1 ↓ 変更後 Protocol 2 空のパスワードログイン禁止 †変更前 #PermitEmptyPasswords no ↓ 変更後 PermitEmptyPasswords no ログを /var/log/secure に出力する †変更前 #SyslogFacility AUTH ↓ 変更後 SyslogFacility AUTHPRIV ログインできるユーザを限定する †限定する場合は指定する AllowUsers username1 username2 再起動 †$ sudo /etc/rc.d/init.d/sshd reload iptablesの設定 †現在の状態を確認する †$ sudo iptables -L ポリシーを決める †$ sudo iptables -P INPUT ACCEPT $ sudo iptables -P FORWARD DROP $ sudo iptables -P OUTPUT ACCEPT ルールをクリアする †$ sudo iptables -F icmp(ping)と自端末からの入力を許可 †$ sudo iptables -A INPUT -p icmp -j ACCEPT $ sudo iptables -A INPUT -i lo -j ACCEPT Web、FTP、POP、smtp、ssh による接続を許可 †$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 110 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 25 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 8000 -j ACCEPT Webmin の接続を許可したい場合 †$ sudo iptables -A INPUT -p tcp --dport 10000 -j ACCEPT FTP の接続を許可したい場合 †$ sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT 使えるねっとなどの Plesk による接続を許可したい場合 †$ sudo iptables -A INPUT -p tcp --dport 8443 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 4643 -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 8880 -j ACCEPT TCPの接続開始と応答、FTPデータなどを許可 †$ sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 確認する †$ sudo iptables -L 他の接続はすべて破棄(ポリシーの再設定) †$ sudo iptables -P INPUT DROP 設定を保存 †iptablesの設定は、サーバを再起動したときとか消えてしまうので、設定を保存しておく(以下のコマンドでファイルに書き出される) $ sudo /etc/init.d/iptables save iptablesの再起動 †$ sudo service iptables restart SSH のポート変更 †ポートを開ける †$ sudo iptables -A INPUT -p tcp --dport ***** -j ACCEPT 設定を保存 †$ sudo /etc/init.d/iptables save iptablesの再起動 †$ sudo service iptables restart 設定ファイル(sshd_config)の修正 †ポートを変更する。 $ sudo vi /etc/ssh/sshd_config 変更前 #Port 22 ↓ 変更後 Port ***** 再起動 †$ sudo /etc/rc.d/init.d/sshd reload 公開鍵の設定 †クライアント側 †Mac のターミナルで公開鍵を作る。 $ ssh-keygen -t rsa $ vim ~/.ssh/id_dsa.pub ※公開鍵の中身が表示される サーバ側 †# su - # mkdir -p /home/username/.ssh # chmod 700 /home/username/.ssh/ # vim /home/username/.ssh/authorized_keys ※公開鍵の中身を貼付ける # chmod 600 /home/username/.ssh/authorized_keys # chown -R username:username /home/username/.ssh/ 設定ファイル(sshd_config)の修正 †パスワード認証を無効にし、鍵でのログインのみ許可する。 # vi /etc/ssh/sshd_config 変更前 #PasswordAuthentication yes ↓ 変更後 PasswordAuthentication no 再起動 †# /etc/rc.d/init.d/sshd reload mkpasswd インストール †インストール †mkpasswd コマンドが使えるように expect をインストールする $ sudo yum install expect 以下のコマンドが使えるようになる $ mkpasswd ログインユーザの確認 †パスワードファイルの確認 †$ cat /etc/passwd apache など ログインさせたくないユーザは、nologin に設定する †$ sudo usermod -s /sbin/nologin username nologin のユーザを作成する場合は、こんな感じ †$ sudo useradd -s /sbin/nologin username ディレクトリを作成しない場合は、こんな感じ? $ sudo useradd -d /dev/null -s /sbin/nologin username useradd: warning: the home directory already exists. Not copying any file from skel directory into it. ユーザのパスワード変更 †mysql や postgres などすでに存在するユーザのパスワードを変更 †$ sudo passwd mysql $ sudo passwd postgres Comment †
Counter: 11811,
today: 4,
yesterday: 4
|