0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

馬鹿の一つ覚え: Linuxユーザ管理

Last updated at Posted at 2017-06-12

ユーザ番号やグループ番号を指定した新規アカウント作成

# groupadd -g 9742 dave    # まずグループ作成
# tail -n1 /etc/group    # 確認
dave:x:9742:
# useradd -g 9742 -u 9742 dave    # ユーザ作成
# tail -n1 /etc/passwd    # 確認
dave:x:9742:9742::/home/dave:/bin/bash
# ls -ld /home/dave    # ホームディレクトリを確認 (Debian系で作られていなかったらmkdir and chown)
drwx------ 3 dave dave 92 Mar 24 23:10 /home/dave
# passwd dave    # 初期パスワードの設定
# id dave
uid=9742(dave) gid=9742(dave) groups=9742(dave)

ユーザに管理者権限を付与

# usermod -aG wheel dave    # アカウントdaveでloginしてsudoできることを確認 (Red Hat系)
# usermod -aG sudo dave    # アカウントdaveでloginしてsudoできることを確認 (Debian系)
# gpasswd -a dave sudo    # コマンドgpasswdを使う場合
# grep -e wheel -e sudo /etc/group    # 確認
# gpasswd -d dave wheel    # グループwheelから削除

ホームディレクトリの変更

# usermod -d /net/gpfs/home/dave dave
# tail -n1 /etc/passwd    # 確認

ホームディレクトリを作らずにアカウント作成

# useradd -M -g 9742 -u 9742 dave

新規グループを作成しユーザを追加

Linuxに新規グループtigressをグループ番号21212で作成し、既存ユーザaliceとbobおよび新規ユーザcarolとdavidの4つを追加してみる。

$ sudo groupadd -g 21212 tigress
$ sudo groupadd -g 21203 carol
$ sudo useradd -g 21203 -u 21203 carol
$ sudo groupadd -g 21204 david
$ sudo useradd -g 21204 -u 21204 david
$ sudo usermod -aG tigress alice
$ sudo usermod -aG tigress bob
$ sudo usermod -aG tigress carol
$ sudo usermod -aG tigress david
$ grep tigress /etc/group
tigress:x:21212:alice,bob,carol,david

グループからユーザを削除

ユーザbobをグループwheelから削除してみる。

$ sudo gpasswd -d bob wheel

ユーザアカウントの最終ログイン日時

$ lastlog -u bob
Username         Port     From             Latest
bob              pts/1    fortigate        Mon Sep 17 13:46:00 +0900 2018

ユーザアカウントの削除 (CentOS, Ubuntu)

ユーザbobを削除。グループも同時に削除される。

$ sudo userdel -fr bob

sudoの警告メッセージを常に表示

$ sudo vi /etc/sudoers.d/privacy
$ sudo cat /etc/sudoers.d/privacy
Defaults	lecture = always
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?