1. motd の変更
FreeBSD をインストールたままの状態であれば、ログインする度に、以下のようなメッセージが表示されます。
Last login: 前回ログインした日時 from IPアドレス
FreeBSD 9.2-RELEASE (GENERIC) #0 r255898: Fri Sep 27 03:52:52 UTC 2013
Welcome to FreeBSD!
Before seeking technical support, please use the following resources:
o Security advisories and updated errata information for all releases are
at http://www.FreeBSD.org/releases/ - always consult the ERRATA section
for your release first as it's updated frequently.
o The Handbook and FAQ documents are at http://www.FreeBSD.org/ and,
along with the mailing lists, can be searched by going to
http://www.FreeBSD.org/search/. If the doc package has been installed
(or fetched via pkg_add -r lang-freebsd-doc, where lang is the
2-letter language code, e.g. en), they are also available formatted
in /usr/local/share/doc/freebsd.
If you still have a question or problem, please take the output of
`uname -a', along with any relevant error messages, and email it
as a question to the questions@FreeBSD.org mailing list. If you are
unfamiliar with FreeBSD's directory layout, please refer to the hier(7)
manual page. If you are not familiar with manual pages, type `man man'.
Edit /etc/motd to change this login announcement.
FreeBSD 10.0 RELEASE
Last login: 前回ログインした日時 from IPアドレス
FreeBSD 10.1-RELEASE (GENERIC) #0 r274401: Tue Nov 11 22:51:51 UTC 2014
Welcome to FreeBSD!
Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories: https://www.FreeBSD.org/security/
FreeBSD Handbook: https://www.FreeBSD.org/handbook/
FreeBSD FAQ: https://www.FreeBSD.org/faq/
Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
FreeBSD Forums: https://forums.FreeBSD.org/
Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with: pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.
Show the version of FreeBSD installed: freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages: man man
FreeBSD directory layout: man hier
Edit /etc/motd to change this login announcement.
FreeBSD 10.1 RELEASE
ここはお好みになりますが、毎回これが表示されるのはうっとうしい気もします。
このメッセージを表示しないようにするには
/home/ユーザ
/ に .hushlogin というファイルを置く
/etc/login.conf から「:welcome=/etc/motd:\」という行を削除する
/etc/ssh/sshd_config に「PrintMotd no」と記述する
などの方法があるのですが、例えば .hushlogin を置くとログイン後、いきなりプロンプトが表示されます。
これはいささかさびしいので、このあたりの落としどころとして、motd というファイルを編集するという方法があります。
メッセージとして表示されている文字列は /etc/motd というファイルの中身を表示しているのです。
エディタを使って、motd の中身を編集します。心配な方は、motd のオリジナルをどこかにコピーしてバックアップを取っておきます。
FreeBSD 10.2-RELEASE (GENERIC) #0 r286666: Wed Aug 12 19:31:38 UTC 2015
Welcome to FreeBSD!
くらいにしておくと、バランスの良い Welcome メッセージになります。
インストール時に game をインストールしていると FreeBSD のヒント(tips)がログイン時に出力されますが、それを抑止するには $HOME/.login の
# $FreeBSD: src/share/skel/dot.login,v 1.17.2.1.8.1 2012/03/03 06:15:13 kensmith Exp $
#
# .login - csh login script, read by login shell, after `.cshrc' at login.
#
# see also csh(1), environ(7).
#
if ( -x /usr/games/fortune ) /usr/games/fortune freebsd-tips
最下行をコメントアウトします。
2. shell の変更
デフォルトでは、shell は csh が設定されています。もし、shell を変えたい場合は、以下のように行います。例として、tcsh を使用する場合を記述しています。
csh のまま変更しない場合は、ここは読み飛ばしてください。
現在の shell を見るには
> echo $SHELL
とします。
FreeBSD 4.2-RELEASEより、tcsh は標準で実装されています。
> chsh
と入力します。
これでエディタが起動されますので、編集します。
(ユーザ名を foo)とします。
#Changing user information for foo.
Login: root
Password: "パスワードを暗号化した文字列"
Uid [#]: 0
Gid [# or name]: 0
Change [month day year]:
Expire [month day year]:
Class:
Home directory: /root
Shell: /bin/csh "← これがシェルの定義になりますので、使用したいシェルをフルパスで記述します"
Full Name: Charlie &
Office Location:
Office Phone:
Home Phone:
Other information:
に変更してください。保存して終了すると
/etc/一時ファイル名: 行数 lines, 文字数 characters.
chsh: user information updated
と変更された旨がメッセージ表示されます。
実際に変更した内容が有効化されるのは、ログアウトしてログインしなおしてからですので、早速使用する場合はログインしなおします。
3. ユーザの追加
ユーザの追加方法です。
ユーザを追加するコマンドは adduser です。(Linux の場合 useradd になります このあたり微妙な違いです)
ユーザ追加時のテンプレートファイルを作成するには useradd -C で行います。
Uid (Leave empty for default):
Login group []:
Enter additional groups []:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]: ← デフォルトのシェルを変更する場合ここに入力します
Home directory [/home/]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Lock out the account after creation? [no]:
Pass Type : yes
Class :
Groups :
Home : /home/
Home Mode :
Shell : /bin/tcsh
Locked : no
OK? (yes/no): yes "← 設定に問題がない場合 [yes] を入力します"
Re-edit the default configuration? (yes/no): no "← 再度編集しない場合 [no] を入力します"
Goodbye!
テンプレートが作成されたら、実際にユーザを追加します。
Username: ユーザ名を入力します
Full name:
Uid (Leave empty for default):
Login group [ユーザ名]:
Login group is ユーザ名. Invite ユーザ名 into other groups? []:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]: tcsh
Home directory [/home/ユーザ名]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password: パスワードを入力します(エコーされません)
Enter password again: パスワードを再度入力します
Lock out the account after creation? [no]:
Username : ユーザ名
Password : *****
Full Name :
Uid : ユーザID
Class :
Groups : グループ名
Home : /home/ホームディレクトリ
Home Mode :
Shell : /bin/tcsh
Locked : no
OK? (yes/no):
adduser: INFO: Successfully added (ユーザ名) to the user database.
Add another user? (yes/no): no ← 続けてユーザを作成する場合は [yes] です
Goodbye!
4. /usr/share/skel の変更
/usr/share/skel というディレクトリにユーザ追加時にデフォルトで設定される項目のテンプレートが用意されています。
たとえばここの dot.cshrc というファイルを編集しておけば、ユーザ追加の度に .cshrc を編集したりすることがなくなりますので便利です。
テンプレート作成のついでに .cshrc に記述しておくと便利な項目を紹介します。(あくまでも個人的な趣味ですので、それぞれいろいろ工夫する余地はたくさんあると思います)
/usr/share/skel/dot.cshrc を編集します。
alias ci ci -l ← RCS を使いやすくする設定です
alias h history 1000 ← history の数を変更します
alias j jobs -l
alias ls ls -aG ls の時点で .ではじまるファイルを表示、カラーで出力します
alias la ls -aF
alias lf ls -FA
alias ll ls -lAF
# A righteous umask
umask 22
set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)
setenv EDITOR vi
setenv PAGER more
setenv BLOCKSIZE K
if ($?prompt) then
# An interactive shell -- set some stuff up
set prompt = "%N@%m:%~ %# "
set promptchars = "%#"
set filec
set history = 1000 ← history の数を変更します
set savehist = (1000 merge) ← merge をいれておくと別の端末からの history もマージされます
set autolist = ambiguous
# Use history to aid expansion
set autoexpand
set autorehash
set mail = (/var/mail/$USER)
if ( $?tcsh ) then
bindkey "^W" backward-delete-word
bindkey -k up history-search-backward
bindkey -k down history-search-forward
set prompt='%/ > ' ← プロンプトを編集します(注1)
endif
setenv TERM kterm-color ← 端末をカラーモードにします
endif
注1
プロンプトを編集すると作業がやりやすくなります。プロンプト編集の代表的な書式を紹介しておきます。