WEBの勉強ノート
Loading

ユーザーの作成・削除・変更

2009 年 5 月 13 日 カテゴリー: ユーザー・グループ

ユーザーの作成

ユーザーの作成には、useradd コマンドを使用。passwd コマンドでパスワードを加えることで初めて使用できるようになる。ユーザーのデフォルト設定は useradd  -D で確認することができる。

[root@centos ~]# useradd centos[root@centos ~]# passwd centosChanging password for user centos.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@centos ~]#

ユーザーの削除(根こそぎ)

ユーザーの削除は userdel だけど、ユーザーが所有していたファイルはそのまま残る。userdel ?r でホームディレクトリのファイルとメールスプールも削除される。

[root@centos ~]# userdel centos -r

その他の場所のユーザーが所有していたファイルやディレクトリも削除したい場合は、削除を行う前にユーザーの uid を確認して、find コマンドで該当の uid が所有者となっているファイルを検索し、何か出てきたら rm -f とか rm -rf とかで消す。

[root@centos ~]# cat /etc/passwd
(省略)
centos:x:501:501::/home/user02:/bin/bash
[root@centos ~]# find / -uid 501

ユーザーをグループに追加

ユーザーをグループに追加するには、ユーザーの属性を変更する usermod コマンドで ?G グループの変更オプションを使用

[root@centos ~]# usermod -G wheel user

コメントをどうぞ