2021/07/04

Let's Encrypt の無料証明書を発行・管理する certbot-auto が Debian/Ubuntu OS で非対応になりました。certbot と python3-certbot-apache をインストールしてサーバ証明書の管理をします。

Apache の ServerName 設定

/etc/apache2/sites-available/000-default.conf ファイルで ServerName にドメインを設定します。

$ sudo vi /etc/apache2/sites-available/000-default.conf

        ServerName ドメイン
...
Bash

certbot と python3-certbot-apache のインストールと設定

certbot で Apache の設定を読み込んで実行し、各設問に答えて設定します。

更新通知のメールアドレスを入力します。

$ sudo certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel):メールアドレス
Bash

A を入力して同意します。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
(A)gree/(C)ancel: A
Bash

Electronic Frontier Foundation からのお知らせを受けてとるか答えます。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Bash

対象のドメインを番号で選択します。

Which names would you like to activate HTTPS for?
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
1: xxxxxxxxx
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):1
Bash

HTTP接続のときに HTTPSにリダイレクトするかを選択します。

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
1: No redirect - Make no further changes to the webserver configuration. 
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration.
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Bash

Congratulations! のメッセージが表示されれば設定完了です。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Congratulations! You have successfully enabled https://logicoya.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=xxxx 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
...
Bash

サーバ証明書の有効期限更新を確認

今回の設定でサーバ証明書が自動更新されますが、certbot.timer でサーバ証明書の有効期限や次回更新日時を確認できます。

$ sudo systemctl status certbot.timer
● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Sun 2021-07-04 15:06:16 JST; 44min ago
    Trigger: Mon 2021-07-05 09:59:24 JST; 18h left
   Triggers: ● certbot.service

Jul 04 15:06:16 xxxx systemd[1]: Started Run certbot twice daily.
Bash

サーバ証明書更新テスト

certbot でサーバ証明書の更新ができますが、 --dry-run でテストできます。

$ sudo certbot renew --dry-run
Bash

  2020/01/12

yarn は npm と互換性のあるパッケージマネージャで、少しずつ使われるようになっている感じです。 

概要

  • npm よりインストールが速い
  • npmと一緒に使える
  • npm で発生するトラブル(依存)が起こりにくい(?)
  • package.json, node_modules/で構成
  • npm よりもモジュールバージョンを細かく指定可能
  • インストールされたバージョンを yarn.lock に保存 実際に高速で、Mac で npm でエラーになったものも yarn だと解決することもありました。 (ただ、逆もあるかも知れませんが)

参考

nvm インストール

nvm インストール

yarn インストール *管理者権限

apt-key を追加

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
Bash

「/etc/apt/sources.list.d/yarn.list」に stable のURLを追加

echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
Bash

アップデート&インストール

aptitude update
aptitude install yarn
Bash

バージョン確認

$ yarn -version
1.21.1
Bash

npm & yarnの脆弱性

2020/1/12:バージョンを最新にしておく npmとyarnの脆弱性とpostinstall - Cybozu Inside Out | サイボウズエンジニアのブログ

基本

プロジェクト作成

$ mkdir yarn_sample
$ cd yarn_sample
$ yarn init
yarn init v1.21.1
question name (www): yarn_sample
question version (1.0.0): 0.0.1
question description: yarn sample
question entry point (index.js): 
question repository url: 
question author: yoo
question license (MIT): 
question private: 
success Saved package.json
Done in 63.65s.
Bash

package.json が作成される

{
  "name": "yarn_sample",
  "version": "0.0.1",
  "description": "yarn sample",
  "main": "index.js",
  "author": "yoo",
  "license": "MIT"
}
HTML

パッケージ追加

$ yarn add [package]
$ yarn add [package]@[version]
$ yarn add [package]@[tag]
Bash

  2020/01/05

Macで npm install すると パッケージ依存によっては Pythonのバージョンが新しすぎてエラーになる。

$ npm install
gyp ERR! find Python 
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - executable path is "/Users/yoo/.pyenv/versions/3.7.1/bin/python"
gyp ERR! find Python - version is "3.7.1"
gyp ERR! find Python - version is 3.7.1 - should be >=2.6.0 <3.0.0
gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
Bash

上記の場合、Mac はPython3.7系だが、npm install のライブラリが 2.7 でないとインストールできない模様

$ npm install --python=python2.7
Bash

yarn を利用する

npm でインストールがエラーになる場合は、互換性のある yarn を利用するのも良いかも知れない。 yarn インストール

  2019/12/22

Nginxで無料証明書「Let's Encrypt」を利用してみる。
「Let's Encrypt」は非営利団体の ISRG (Internet Security Research Group) が運営している、証明書の発行・インストール・更新を無料利用することができる。

インストール

Ubuntu18には「certbot」パッケージがあるのでインストール

# apt-get install certbot
Bash

※後々の設定でうまくいきませんでした。

# git clone https://github.com/certbot/certbot
Bash

こちらは、ソースないの「certbot-auto」が利用できる。

証明書の作成

certbot の場合

※設定がうまくいきませんでした。

# certbot certonly -d ドメイン名
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 
Bash

ここで、こけました。

certbot-auto の場合

certbot-auto を実行すると、Apache か Nginx 聞かれる。
この辺は、サーバ設定によりますが Nginx 個人的事情で問題があったので Apacheにしました。

# ./certbot-auto -d ict-kids.net
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate and install certificates?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Apache Web Server plugin (apache)
2: Nginx Web Server plugin (nginx)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 
...
Bash

https にリダイレクトするか聞かれますが、とりあえずリダイレクトしないようにしました。

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Bash

設定がうまくいくと、以下のファイルが書き出される。

/etc/letsencrypt/live/ドメイン名/fullchain.pem
/etc/letsencrypt/live/ドメイン名/privkey.pem
Bash

Apache の場合

以下のパスにファイルを作成されたようです。

Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf
Bash

Nginx の場合

/etc/nginx/site-avaible/xxxx ファイルにSSLの設定を記述する

server {
        listen 443 default_server ssl;
        listen [::]:443 ssl default_server;
        server_name ドメイン名;

        ....
        ssl_certificate /etc/letsencrypt/live/ドメイン名/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/ドメイン名/privkey.pem;
        ....
}
Bash

Let's Encrypt の更新

90日で証明書の有効期限が切れるため、crontabなどで定期的に更新スクリプトを実行する必要がある。

※2020/04/09 更新

/root/src/certbot/certbot-auto renew --post-hook "service apache2 restart"
Bash

  2019/12/22

Apache2.4 を起動したところ以下のエラー

client denied by server configuration
Bash

/etc/apache2/apache2.conf の設定をみると

        Options FollowSymLinks
        AllowOverride None
        Require all denied



        AllowOverride None
        Require all granted



        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted



        Require all denied

Bash

基本的に拒否の設定になっているので、/etc/apache2/sites-available/000-default.conf に個別設定する必要がある。

    ...
    Require all granted
    ....

Bash

  2019/12/22

Ubuntuのユーザ関連のコマンドは、Debianと異なるようだ。

rootログイン

$ sudo su -
Bash

sudo権限

sudo権限もつけておく

$ sudo gpasswd -a xxx sudo
Bash

  2019/08/09

Debian9系だとNode.jsのバージョンが古く npmもインストールできないので、パッケージを更新してからインストールする。

# curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# aptitude installl nodejs
# nodejs -v
v10.16.2
# npm -v
6.9.0
Bash

  2019/03/26

upgrade などしてしまって、PHP7.2のパッケージが消失してしまう。

以下を参照 How To Install PHP (7.3, 7.2 & 5.6) on Debian 9 Stretch

PHP7.2を Debian 9(stretch)にインストールする方法

<

p class="code">$ sudo apt-get install apt-transport-https lsb-release ca-certificates $ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg $ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list 認証して、/etc/apt/sources.list.d/ に php.list を新たに追加している模様

  2018/07/05

install libgl1-mesa-glx

import matplotlib as mpl mpl.use('Agg')

  2015/04/23

FTPサーバは「vsftpd」をインストールする。

aptitude install vsftpd

vi /etc/vsftpd.conf

<< Top < Prev Next > Last >>