OpenBSDにはユーザを作成するために adduserコマンド と useraddコマンド がある。
adduserコマンド は perlスクリプトファイルで対話的である。
useraddコマンドは バイナリファイルで 対話的でない。
OpenBSD-PINE64$ file `which adduser`
/usr/sbin/adduser: a /usr/bin/perl script text executable
OpenBSD-PINE64$ file `which useradd`
/usr/sbin/useradd: ELF 64-bit LSB shared object, AArch64, version 1
adduserコマンドは問いに答えていくと必要な設定も行える為、1ユーザを作るときに向いている。
OpenBSD-PINE64# adduser
Use option ``-silent'' if you don't want to see all warnings and questions.
Reading /etc/shells
Check /etc/master.passwd
Check /etc/group
Ok, let's go.
Don't worry about mistakes. There will be a chance later to correct any input.
Enter username []: bsduser
Enter full name []:
Enter shell csh ksh nologin sh [ksh]:
Uid [1001]:
Login group bsduser [bsduser]:
Login group is ``bsduser''. Invite bsduser into other groups: guest no
[no]:
Login class authpf bgpd daemon default pbuild staff unbound
[default]:
Enter password []:
Enter password again []:
Name: bsduser
Password: ****
Fullname: bsduser
Uid: 1001
Gid: 1001 (bsduser)
Groups: bsduser
Login Class: default
HOME: /home/bsduser
Shell: /bin/ksh
OK? (y/n) [y]:
useraddコマンドは対話的ではないため様々な設定を個別に行う必要がある。
以下は useraddコマンドでbsduserを作成したところである。
OpenBSD-PINE64# useradd bsduser
useradd: Warning: home directory `/home/bsduser' doesn't exist, and -m was not specified
OpenBSD-PINE64# id bsduser
uid=1001(bsduser) gid=1001(bsduser) groups=1001(bsduser)
/home/bsduser ディレクトリがないことを注意されたので作成しておく。
OpenBSD-PINE64# mkdir /home/bsduser
作ったホームディレクトリの所有者を変更する。
OpenBSD-PINE64# ls -lF /home/
drwxr-xr-x 2 root wheel 512 Apr 21 04:12 bsduser/
OpenBSD-PINE64# chown bsduser:bsduser /home/bsduser/
OpenBSD-PINE64# ls -lF /home/
drwxr-xr-x 2 bsduser bsduser 512 Apr 21 04:12 bsduser/
パスワードの設定をする。
OpenBSD-PINE64# passwd bsduser
Changing password for bsduser.
New password:
Retype new password:
弱いパスワードだと注意される。
OpenBSD-PINE64# passwd bsduser
Changing password for bsduser.
New password:
Please don't use an all-lower case password.
Please use a different password. Unusual capitalization,
control characters, or digits are suggested.
New password:
最後に初期設定ファイルが /etc/skel/ディレクトリにある。
ここのファイルを各ユーザのホームディレクトリにコピーすればよい。
コピーした後のファイルはそのホームディレクトリのユーザが所有者になっていないとアクセスできないので注意。
OpenBSD-PINE64# ls -alF /etc/skel/
total 36
drwxr-xr-x 3 root wheel 512 Apr 17 21:16 ./
drwxr-xr-x 22 root wheel 1536 Apr 21 04:20 ../
-rw-r--r-- 1 root wheel 87 Apr 17 20:25 .Xdefaults
-rw-r--r-- 1 root wheel 771 Apr 17 20:25 .cshrc
-rw-r--r-- 1 root wheel 101 Apr 17 20:25 .cvsrc
-rw-r--r-- 1 root wheel 359 Apr 17 20:25 .login
-rw-r--r-- 1 root wheel 175 Apr 17 20:25 .mailrc
-rw-r--r-- 1 root wheel 215 Apr 17 20:25 .profile
drwx------ 2 root wheel 512 Apr 17 21:16 .ssh/
OpenBSD-PINE64# ls -alF /etc/skel/.ssh/
total 8
drwx------ 2 root wheel 512 Apr 17 21:16 ./
drwxr-xr-x 3 root wheel 512 Apr 17 21:16 ../
-rw------- 1 root wheel 0 Apr 17 20:25 authorized_keys
OpenBSD-PINE64# cp -r /etc/skel/.* /home/bsduser/
OpenBSD-PINE64# chown -R bsduser /home/bsduser/.*
OpenBSD-PINE64# ls -alF /home/bsduser/
total 36
drwxr-xr-x 3 bsduser bsduser 512 Apr 21 04:25 ./
drwxr-xr-x 4 root wheel 512 Apr 21 04:12 ../
-rw-r--r-- 1 bsduser bsduser 87 Apr 21 04:25 .Xdefaults
-rw-r--r-- 1 bsduser bsduser 771 Apr 21 04:25 .cshrc
-rw-r--r-- 1 bsduser bsduser 101 Apr 21 04:25 .cvsrc
-rw-r--r-- 1 bsduser bsduser 359 Apr 21 04:25 .login
-rw-r--r-- 1 bsduser bsduser 175 Apr 21 04:25 .mailrc
-rw-r--r-- 1 bsduser bsduser 215 Apr 21 04:25 .profile
drwx------ 2 bsduser bsduser 512 Apr 21 04:25 .ssh/
OpenBSD-PINE64# ls -alF /home/bsduser/.ssh/
total 8
drwx------ 2 bsduser bsduser 512 Apr 21 04:25 ./
drwxr-xr-x 3 bsduser bsduser 512 Apr 21 04:25 ../
-rw------- 1 bsduser bsduser 0 Apr 21 04:25 authorized_keys