懲りずにまたLTSPクライアントのカスタマイズしてみた-rootpass編

id:hykt:20081030に続くid:hykt:20081104の続き。
LTSPについて、どうしてもクライアント自身にログインしてそこそこ使える環境を作ってみたくて、再び調べてみた。

どうやってアプローチするのか考えた結果、まず、クライアントのディスクイメージを作成するときに実行する ltsp-build-client コマンドは、どんな処理をしているのか調べてみることにした。

hykt@ubuntu-desktop:~$ which ltsp-build-client
/usr/sbin/ltsp-build-client
hykt@ubuntu-desktop:~$ file /usr/sbin/ltsp-build-client 
/usr/sbin/ltsp-build-client: Bourne-Again shell script text executable
hykt@ubuntu-desktop:/~$ 

ふむふむ。中身はシェルスクリプトなんだ。ということで、その内容を見てみると…。

hykt@ubuntu-desktop:~$ more /usr/sbin/ltsp-build-client 

コマンドにオプションが指定できるようだ。しかも --help オプションで、指定できるオプションの一覧が表示されそうだ。

hykt@ubuntu-desktop:~$ /usr/sbin/ltsp-build-client --help
LTSP Build Client usage:

  ltsp-build-client 

Regular options:
    --dist                     Set the distribution to be used for install
    --extra-help               Display help for all available commandline options
    --help                     Display this help message
    --mirror                   Set the mirror location
hykt@ubuntu-desktop:~$ 

--extra-help オプションで、さらに詳しいオプションが表示されるとのこと。

hykt@ubuntu-desktop:~$ /usr/sbin/ltsp-build-client --extra-help
LTSP Build Client usage:

  ltsp-build-client 

Regular options:
    --dist                     Set the distribution to be used for install
    --extra-help               Display help for all available commandline options
    --help                     Display this help message
    --mirror                   Set the mirror location

Advanced options:
    --accept-unsigned-packages allow unsigned packages during install.
    --apt-keys                 include the listed keys in the apt keyring
    --arch                     set the target architecture
    --base                     Set the default base install directory
    --chroot                   Set the name of the chroot.
    --components               Set the components to be used in mirror
    --config                   Load a user specific configuration file
    --copy-package-cache       cache downloaded packages
    --copy-sourceslist         use the servers sources.list instead of generating one
    --debconf-seeds            load debconf seeding in the chroot after install
    --debug                    Enable debug support
    --early-mirror             add a mirror, which takes priority over the default mirror
    --early-packages           set the list of packages to install after base-install is completed.
    --exclude                  exclude packages from the initial chroot
    --extra-mirror             add a mirror, with lower priority than the default mirror
    --keep-packages            keep cache of downloaded package files
    --kiosk                    a simple webkiosk mode.
    --late-packages            list of packages to install as part of the final installation.
    --locale                   Set the default locale
    --mythbuntu                create a Mythbuntu fat client.
    --mythbuntu-copy-user-credentials Mythbuntu: copy login credentials from current user
    --mythbuntu-user-credentials Mythbuntu: specify login credentials as username:password
    --prompt-rootpass          prompt to set the root password, defaults to disabled
    --security-mirror          add a security mirror
    --serial-console           enable serial console
    --skipimage                force to skip the squashfs build (for debian-installer).
hykt@ubuntu-desktop:~$ 
…こんなにたくさんオプションがあったのか…。
そして、気になるオプションがあるな…
--kiosk シンプルなWebキオスクモード
--mythbuntu Mythbuntuのfat clientを作成する
--prompt-rootpass rootパスワードを設定するためのプロンプトを表示する
デフォルトでは無効
Webブラウザだけのキオスク端末を作成するモードやfatクライアントを作成するモードもある。
僕が作りたかったクライアントは、fat clientと呼ばれているみたいだな。
そして、デフォルトで無効になっていたrootアカウントは、有効にするためのオプションが用意されていたんだ。 このkioskとfatclientをキーワードにして検索したところ、次のドキュメントを見つけた。 fatclientに関するドキュメントでは、LTSPクライアントのカスタマイズについて参考になるし、kioskに関するドキュメントではkiosk端末作成の際のltsp-build-clinetコマンドのプラグインの記述について参考になる。

それじゃ、まずは試しにrootアカウントを有効にしたディスクイメージを作ってみよう。

hykt@ubuntu-desktop:/opt/ltsp$ sudo ltsp-build-client --prompt-rootpass
途中でrootアカウントのパスワードを設定するプロンプトが表示されたので、入力する。
で、ディスクイメージの作成が終わったら、クライアントをネットワークブートして、[Ctrl]+[Alt]+[F1]でコンソール画面を表示して、rootでログインしてみる。
Ubuntu 8.04 ltsp tty1



ltsp login: root
Password:
Your account has expired; please contact your system administrator

User account has expired
あららのら。ログインできないじゃん。
なんで?ということで、作成されたディスクイメージの基のファイル(/opt/ltsp/i386)のpasswdファイルとshadowファイルを見てみる。
hykt@ubuntu-desktop:~$ sudo chroot /opt/ltsp/i386
root@ubuntu-desktop:/# vipw             ←passwdファイルを見てみた
root@ubuntu-desktop:/# vipw -s          ←shadowファイルを見てみた
root:$1$ydu6gaz8$pCcLO8N.Pl24CVO2NaMcH/:14194:0:99999:7::1:
あれ?rootアカウントにパスワードは設定されているけど、使用不能になっているじゃん。
…ということが:(コロン)で区切られた各フィールドの意味から分かる。
man shadowで表示されるオンラインマニュアルと上記のrootアカウントの各フィールドの値を照らし合わせると、次のようになる。
root ログイン名
$1$ydu6gaz8$pCcLO8N.Pl24CVO2NaMcH/ 暗号化されたパスワード
14194 1970 年 1 月 1 日から、最後にパスワードが変更された日までの日数
0 パスワードが変更可能となるまでの日数
99999 パスワードを変更しなくてはならなくなる日までの日数
7 パスワード有効期限が来る前に、ユーザが警告を受ける日数
  パスワード有効期限が過ぎてからアカウントが使用不能になるまでの日数
1 1970 年 1 月 1 日からアカウントが使用不能になる日までの日数
  予約フィールド
後ろから2番目のフィールドに1が設定されているので、これじゃrootアカウントは1970年1月1日しか使えない。
--prompt-rootpassオプションで、rootアカウントのパスワードを設定して利用できる状態になるんじゃないの?
………。
確かに、prompt-rootpassはしてて、オプション名はenable-rootaccountではないけどさ…って、そういうこと?

とりあえず、アカウントを使用可能にするために、このフィールドに設定されている1を削除して、ディスクイメージを更新する。

root@ubuntu-desktop:/# vipw -s
root:$1$ydu6gaz8$pCcLO8N.Pl24CVO2NaMcH/:14194:0:99999:7::1:   [編集前]
 ↓
root:$1$ydu6gaz8$pCcLO8N.Pl24CVO2NaMcH/:14194:0:99999:7:::    [編集後]
root@ubuntu-desktop:/# exit
hykt@ubuntu-desktop:~$ sudo ltsp-update-image 

で、ディスクイメージの更新が終わったら、クライアントをネットワークブートして、[Ctrl]+[Alt]+[F1]でコンソール画面を表示して、rootでログインしてみる。

Ubuntu 8.04 ltsp tty1



ltsp login: root
Password:
[プロンプトが表示される]
こんどは、うまくいった。
しかし、なんでこんな仕様になっているんだろう…。

さて、今日はここまででおなかいっぱいなので、続きはまた次回に。