6
6

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.

DigitalOcean の CentOS7 初期セットアップ手順

Last updated at Posted at 2014-10-20

DigitalOcean の CentOS 7 のセットアップの手順。

Digitalocean の Initial Server Setup with CentOS 7 を参考にする。

仮想マシンの起動

スペックは一番低いやつでOK。後から変更が可能。
OS は CentOS 7 を選択。
SSH キーは登録したものを設定する。これが root の公開鍵に設定される。

droplets の Access の画面で IP アドレスや root のパスワードが確認できるので、 root のパスワードをリセットしておく。リセットしたパスワードはメールで届く。

SSHログイン

$ ssh -i 秘密鍵 root@IPアドレス

基本的な設定など

ログインしたら root で下記の作業をする。

yum upddate とだいたい必要そうなパッケージをインストール

# yum update

# yum -y groupinstall base
# yum -y groupinstall network-tools

reboot

カーネルなどもアップグレードされているので reboot する。

# reboot

SSHのセキュリティ設定

# vi /etc/ssh/sshd_config

下記の部分を編集する。

PasswordAuthentication no
Port 任意のポート番号 ( 22 以外にしておく )

sshd を再起動する。

# systemctl restart sshd.service

ポート番号が変わっていることを確認する

# ss -antu | grep ssh

SeLinux の設定。

selinux で /etc/ssh/sshd_config に設定したポート番号への接続を許可する。

# semanage port -a -t ssh_port_t -p tcp 設定する任意のポート番号

ユーザーの追加

基本的に root ユーザーで作業はしないのでユーザーを追加する。

# useradd {USERNAME}
# passwd {USERNAME}

追加したユーザーが sudo を実行できるように wheel グループに追加する

# usermod -aG wheel {USERNAME}

追加したユーザーに切り替える

# su {USERNAME}

公開鍵を設定する

$ cd
$ mkdir .ssh
$ chmod 700 .ssh
$ vi .ssh/authorized_keys # 公開鍵を記載
$ chmod 600 .ssh/authorized_keys

root ユーザーに戻って、 root での ssh ログインを禁止する

# vi /etc/ssh/sshd_config

PermitRootLoginno にする。

PermitRootLogin no

sshd を再起動する。

$ systemctl restart sshd.service

Cloud Firewalls の設定

Cloud Firewalls で、今回変更した SSH ポート番号だけでしか SSH ログインできないように Firewall の設定を追加する。

6
6
0

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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?