0
1

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.

ConoHa環境構築メモ

Last updated at Posted at 2019-12-17

環境

ConoHa VPS


$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"

作業ユーザーの作成


$ add user lambda34 # ユーザーの追加

$ password     # パスワードの設定

$ gpasswd -a lambda34 sudo # ユーザーをグループに所属させる

SSH設定

  1. ローカルPC側で公開鍵を作成

$ ssh-keygen -t rsa

公開鍵と秘密鍵が作成されていることが確認できます。


$ ls -la ~/.ssh
total 72
drwx------   9 aaa  staff   288 10 12 23:34 .
drwxr-xr-x+ 59 aaa  staff  1888 12  8 04:07 ..
-rw-------   1 aaa  staff  1843 12  8 17:03 id_rsa
-rw-r--r--   1 aaa  staff   413 12  8 17:03 id_rsa.pub
  1. VPS側のディレクトリに公開鍵を設置

$ scp ~/.ssh/id_rsa.pub root@xxx.xx.xx.xx:~/ 
  1. VPC側で公開鍵をユーザーディレクトリに設置

$ ssh root@xxx.xx.xx.xx

$ mv ~/id_rsa.pub ~lambda34/.ssh/authorized_keys

$ chown -R lambda34: ~lambda34/.ssh

$ chmod 700 ~lambda34/.ssh

$ chmod 600 ~lambda34/.ssh/authorized_keys

rootユーザーでVPCに入り、公開鍵を先ほど作成したlambda34のユーザーディレクトリ
に設置。権限を変えておきます。

ローカルPC側から作成したユーザーで接続ができることを確認してください


$ ssh -i ~/.ssh/id_rsa lambda34@xxx.xx.xx.xx 

セキュリティ設定

rootユーザーでのログインができないようにsshd_configを編集します。

編集前にバックアップをしておく


$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bac 

$ sudo vi /etc/ssh/sshd_config
↓
Port 65656                # port22は推測されるので別portに変更
PermitRootLogin no        # ルートディレクトリでのログインを禁止
PasswordAuthentication no # パスワードでのログインを禁止

再起動


$ sudo service ssh restart 

rootユーザーでログインできなくなっていることの確認


$ ssh -p 65656 -i ~/.ssh/id_rsa root@xxx.xx.xx.xx
root@xxx.xx.xx.xx's password:
Permission denied, please try again

port指定と秘密鍵を使用してログインする場合


$ ssh -p 65656 -i ~/.ssh/id_rsa lambda34@xxx.xx.xx.xx

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

デフォルトではinactiveになっているはず。


$sudo ufw status
[sudo] password for lambda34:
Status: inactive

有効化


$ sudo ufw enable

アクセスはデフォルトで拒否設定にする


$ sudo ufw default deny

必要なプロトコルの通信のみ許可
ここではport80と443を開放します。


$ sudo ufw allow https/tcp
$ sudo ufw allow http/tcp

確認コマンド


$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
443/tcp                    ALLOW IN    Anywhere
80/tcp                     ALLOW IN    Anywhere
65656                      ALLOW IN    Anywhere
443/tcp (v6)               ALLOW IN    Anywhere (v6)
80/tcp (v6)                ALLOW IN    Anywhere (v6)
65656 (v6)                 ALLOW IN    Anywhere (v6)

再度読み込み


$ sudo ufw reload
Firewall reloaded

パッケージのアップデート


$ sudo apt-get update

dockerのインストール


$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
    - y

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo apt-key fingerprint 0EBFCD88

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

$ sudo apt-get update

$ sudo apt-get install docker-ce -y

Dockerの自動起動設定


$ sudo systemctl enable docker

ユーザーをDockerグループに追加


$ sudo usermod -aG docker $USER

docker-compose のインストール


$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

$ sudo chmod +x /usr/local/bin/docker-compose

$ exit

作業ディレクトリの作成


$ sudo mkdir -p /data/repo
$ sudo chown -R $USER /data
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?