Linux にログインできないユーザを作成する

ログイン出来ないユーザを作成する場合は以下

useradd -s /sbin/nologin hoge

ログインしないからホームディレクトリも作らない場合は -M オプション利用

useradd -s /sbin/nologin -M hoge

/sbin/nologin/bin/false どちらを利用するか迷った
参考にさせていただきました。

SSH ログインさせないアカウントを作る - Ceekz Logs (Move to y.ceek.jp)

知らないと危険な false と nologin の挙動の違い #Linux #BSD

gem install mysql2 でエラー

mysql2 が含まれている Gemfile を使って bundle install してるときにエラーが出ました。

$ bundle install --path vendor/bundle --without development test

Gem files will remain installed in /home/hoge/fuga/vendor/bundle/ruby/2.1.0/gems/mysql2-0.3.15 for inspection.
Results logged to /home/hoge/fuga/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.15/gem_make.out
An error occurred while installing mysql2 (0.3.15), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.15'` succeeds before bundling.

言われるがままに mysql2 を突っ込んでみたがエラー

$ gem install mysql2 -v '0.3.15'
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    /home/hoge/.rbenv/versions/2.1.1/bin/ruby extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/hoge/.rbenv/versions/2.1.1/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mygcclib
        --without-mygcclib
        --with-mysqlclientlib
        --without-mysqlclientlib

extconf failed, exit code 1

Gem files will remain installed in /home/hoge/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mysql2-0.3.15 for inspection.
Results logged to /home/hoge/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.15/gem_make.out

そもそも mysql.h がないらしい。

$ sudo apt-get install libmysqld-dev

ライブラリをインストールしてあげた後、再度試したら成功。

ubuntu14.04 で diff-highlight: Permission denied

ubuntu 14.04 を使い始めました。
git で diff-highlight を使ってるんですが、

何かうまく動いてなかった。

$ git log
/usr/share/doc/git/contrib/diff-highlight/diff-highlight | less: 1: /usr/share/doc/git/contrib/diff-highlight/diff-highlight | less: /usr/share/doc/git/contrib/diff-highlight/diff-highlight: Permission denied

インストール場所を確認

$ dpkg -L git | grep 'diff-highlight'
/usr/share/doc/git/contrib/diff-highlight
/usr/share/doc/git/contrib/diff-highlight/README
/usr/share/doc/git/contrib/diff-highlight/diff-highlight

権限を確認

$ ls -l /usr/share/doc/git/contrib/diff-highlight/
-rw-r--r-- 1 root root 3811 Mar 19 23:43 diff-highlight
-rw-r--r-- 1 root root 5343 Mar 19 23:43 README

あれ。実行権限ない。

実行権限付与

$ sudo chmod 755 /usr/share/doc/git/contrib/diff-highlight/diff-highlight
$ ls -l /usr/share/doc/git/contrib/diff-highlight
total 12
-rwxr-xr-x 1 root root 3811 Mar 19 23:43 diff-highlight
-rw-r--r-- 1 root root 5343 Mar 19 23:43 README

うん。動いた。

rkhunter の自動起動設定

rkhunter が自動で動いていた。
cron に登録した覚えはないけど…

自動実行の正体

Ubuntu では rkhunter インストール時に /etc/cron.dairy にファイルが配置される。
そのため日次で自動実行される。
安心設計!!!

留意事項

ただ、それを忘れててよくパッケージ更新後とかにひっかかる。
パッケージ更新後には必ず sudo rkhunter --propupd が必要。

すぐ忘れる。 うん。覚悟が足りなかいからだな。

覚悟とは犠牲を払うことではない!
覚悟とは暗闇のなかに進むべき道を切り開くことだ!!
Giorno Giovanna

ELB へのSSL証明書の登録作業

サーバ証明書の再発行を行って登録した。
この辺り人任せだったのでメモ。

Amazon の Developer Guide を参考に実施。
Elastic Load Balancing の SSL 証明書

秘密鍵(PrivateKey)の作成

まず証明書署名要求(Certificate Signing Request)を作成するための、鍵を作成する。

$ openssl genrsa 2048 > hogehoge.pem
証明書署名要求(CSR)の作成

作成した鍵で証明書署名要求を作成する。

$ openssl req -new -key hogehoge.pem -out fugafuga.csr

途中、識別名(Distinguished Name)の各項目の入力が求められるので適宜入力。

作成した証明書承認要求を認証機関(CA)に送付する

認証機関(CA)に送付することで署名が追加され、
pem 形式の電子証明書が返信されてくる。
認証局により異なります。

Elastic Load Balancing (ELB) への証明書更新

以下を参考に実施。

ロードバランサーのSSL証明書の更新

  1. AWS Management Console から EC2 => Load Balancers を選択する。
  2. 更新したい Load Balancer を選択し、 Listners タブを選択する。
  3. SSL Certificate の Change をクリックする。
  4. Upload a new SSL Certificate を選択する。
  5. 下記の項目を設定し Save をクリックする。
    • Certificate Name => 任意
    • Private Key => CSR作成時に利用したもの 
    • Public Key Certificate => 認証機関から送付されたもの
  6. おしまい

PrivateKey の内容を入力する際には pem 形式でなければいけない。
*.key で作成してる場合等は、下記コマンドの出力を入力する。

sudo openssl rsa -in hogehoge.key -outform PEM

ELB への登録は IAM から行ったりと、他にも方法はあるけどこれが簡単だった。

Ubuntu での OpenSSL 脆弱性対応

巷では OpenSSL の脆弱性対応でてんやわんやですね。

みんな大好き Amazon さんはいち早くサポートして下さりありがたいことです。 ホントお世話になっております。

AWS から OpenSSL の脆弱性について AWS のサービスアップデート | アマゾン ウェブ サービス(AWS 日本語)



フハハ。見ろ!Amazonの力を!!人がゴミのようだ!!!
©ロムスカ・パロ・ウル・ラピュタ

とかやってたら盛大にブーメラン喰らいました。
驕れる者は久しからず。
反省してタイトル通りのセキュリティアップグレードです。

Ubuntu Server セキュリティアップデート


運用しているのは Ubuntu Server が多いので公式を参考に対応します。
USN-2165-1: OpenSSL vulnerabilities | Ubuntu

sudo apt-get update
sudo apt-get dist-upgrade
sudo shutdown -r now

パッケージ狙い撃ちで更新したい人は以下のとおり。

sudo apt-get update
sudo apt-get apt-get install openssl libssl1.0.0
sudo shutdown -r now

起動したら確認。

dpkg -l | grep -e openssl -e libssl
openssl version


dpkg1.0.1-4ubuntu5.12 が表示されてたらOKらしい。
openssl versionOpenSSL 1.0.1 14 Mar 2012 となってる。
変わってへんやんけ((((;゚Д゚))))


と密かにうろたえてましたが、
openssl version の結果が実行前と変わらなくても問題ないようです。

security - How to patch CVE-2014-0160 in OpenSSL? - Ask Ubuntu



あとは証明書と鍵だな。