20
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Linuxサーバの初期設定

Last updated at Posted at 2014-08-09

前提

サーバ側:Linux(CentOS 6)
クライアント側:Mac

1. rootパスワードの変更

$ passwd
# 新しいパスワードを入力

2. 一般ユーザ作成

$ useradd ユーザ名
$ passwd ユーザ名 # パスワードを設定
$ usermod -G wheel ユーザ名 # sudoコマンドが使えるように
$ visudo # wheel グループがsudoを使えるように
%wheel ALL=(ALL) ALL # 先頭のコメントアウト(%)を外す

sshでログインできるか確認。コマンドプロンプトの最後が#(rootユーザを表す)じゃなくて$(一般ユーザ)になっているはず。

3. 公開鍵の設定

サーバ側

$ mkdir ~/.ssh # クライアントの公開鍵の保存場所
$ chmod 700 ~/.ssh

クライアント側

$ ssh-keygen -t rsa -v # パスワード設定は任意。基本的にEnter押すだけ
$ chmod 600 ~/.ssh/id_rsa.pub
$ ls -la
-rw-------   1 *****  staff  1766 12 12  2013 id_rsa
-rw-------   1 *****  staff   412 12 12  2013 id_rsa.pub

$ scp ~/.ssh/id_rsa.pub ユーザ名@転送先ホスト:~/.ssh/authorized_keys

sshでログインすると、パスワードを入力せずにログインできる。
パスワードログインを禁止する場合は4.SSHの設定を参照

4. SSHの設定

$ sudo -s # root権限が必要な設定が続くので、rootになっておく
# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.org # 設定ファイルのバックアップを作成
# vim /etc/ssh/sshd_config
Port 任意のポート # デフォルトのポートでsshできないようにする
PasswordAuthentication no # パスワード認証を禁止(鍵認証のみ使用する場合)
PermitRootLogin no # rootでのログインを禁止する

# /etc/rc.d/init.d/sshd reload # 編集した設定を反映

ssh で変更前のポートでログインしようとしても、ログインできない。また、rootでもログインできない。

5. yum のアップデート

# yum update # セキュリティ的に最新の状態にしておく

6. 日本語化

# vim /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"

# date # 日本語になるか確認

7. ファイアーウォールの設定

# iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
# iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
# iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
# iptables -A INPUT -i lo -j ACCEPT 
# iptables -A INPUT -p icmp -j ACCEPT 
# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
# iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# iptables -P INPUT DROP
# iptables -P OUTPUT ACCEPT
# service iptables save # 設定を反映
# iptables -L # 設定を確認
20
26
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?