ラベル Linux の投稿を表示しています。 すべての投稿を表示
ラベル Linux の投稿を表示しています。 すべての投稿を表示

2017年3月28日火曜日

Ubuntu 16.04へのdocker-ceインストール

Docker公式リポジトリからのインストール

Ubuntu 16.04への最新版dockerをインストールする手順の備忘録です。構成管理が楽になるので、バイナリインストールでなく、パッケージ管理システム経由でのインストール手順を記載します。

リポジトリアクセスのためのパッケージ導入

Docker公式リポジトリにHTTPS経由でアクセスするために必要なパッケージをインストールします。
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

リポジトリ検証用の公開鍵導入

Dockerの公式GPG(GNU Privacy Guard)鍵を追加します。インターネットから入手したパッケージが正しい配布元からのものか検証するために用いられます。
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

パッケージ管理システムへのリポジトリ追加

stableリポジトリを追加します。edgeとstableの二種類のリポジトリがあり、edgeは月一のリリースでstableは四半期毎にリリースされる違いです。
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

パッケージ管理システムからのdocker-ceのインストール

$ sudo apt update && sudo apt install docker-ce

Dockerのインストール確認

以下のコマンドでテスト用のイメージをダウンロードし、それをコンテナ内で実行することができます。同じメッセージが出力されることで、インストールが成功したことがわかります。
$ sudo docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/


2017年3月20日月曜日

Linuxアカウント作成、変更、削除

yum, apt等でパッケージからOSSインストールするときには、実行ユーザが自動で作成されることが多いです。しかし、ソースコード、バイナリから導入する場合や自作ツールを導入する場合、自分で実行ユーザを作成する必要があり、そのために手順をメモしておきます。

Debian系では、adduser, deluser, addgroup, delgroupなどのコマンドが用意されていますが、それと比較してローレベルですが、幅広いLinuxディストリビューションで使用できるuseradd, usermod, userdel, groupadd, groupmod, groupdelを使ったアカウント操作方法を記載します。

グループ作成

アカウントを作成するにあたり、まずグループを作成します。
ユーザは必ずひとつ以上のグループに所属する必要があります。
$ groupadd testgroup
$ grep testgroup /etc/group
testgroup:x:1002:

グループ変更

すでに作成したグループのグループ名、グループIDを変更することができます。
$ groupmod testgroup -n testg -g 1003
$ grep testg /etc/group
testg:x:1003:

グループ削除

グループに所属しているユーザが存在する状態では、グループの削除はできません。
まず、削除対象のグループに存在するユーザを無くした上で実行する必要があります。
$ groupdel testg
$ grep testg /etc/group

ユーザ作成

ログイン可能なユーザ作成

bashへのログイン可能なユーザを作成します。
-dオプションでホームディレクトリを指定し、-mオプションでホームディレクトリが存在しない場合に作成するように指定します。
-gオプションで先ほど作成したグループ名を指定し、そのグループの所属ユーザを作成します。
$ useradd testuser -d /home/testuser -m -g testg
$ passwd testuser
$ grep testuser /etc/passwd
testuser:x:1003:1003::/home/testuser:

ログイン不可なユーザ作成

bashへのログイン不可なユーザを作成します。
ここでは、ログイン不可ユーザのログインシェルは/usr/sbin/nologin(RHEL系なら/sbin/nologin)を使いますが、/bin/falseでも良いです。
-sオプションでユーザのログインシェルを/usr/sbin/nologinに指定します。
デフォルトではユーザのログインシェルは/bin/bashが指定されますが、明示的に/usr/sbin/nologinに設定します。
$ useradd testnologin -d /home/testnologin -s /usr/sbin/nologin -m -g testg
$ passwd testnologin
$ grep testnologin /etc/passwd
testnologin:x:1004:1003::/home/testnologin:/usr/sbin/nologin

ユーザ変更

ログイン不可なユーザへの変更

既存のログイン可能のユーザをログイン不可に設定します。
-sオプションでユーザのログインシェルを/usr/sbin/nologinに指定します。
$ usermod testuser -s /usr/sbin/nologin
$ grep testuser /etc/passwd
testuser:x:1003:1003::/home/testuser:/usr/sbin/nologin

ログイン可なユーザへの変更

既存のログイン不可のユーザをログイン可能に設定します。
-sオプションでユーザのログインシェルを/bin/bashに指定します。
$ usermod testuser -s /bin/bash
$ grep testuser /etc/passwd
testuser:x:1003:1003::/home/testuser:/bin/bash

ユーザ削除

ホームディレクトリをまとめて削除

ユーザの削除時に-rオプションを設定しないと、ホームディレクトリが残ります。
$ userdel testuser -r
$ grep testuser /etc/passwd