0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux] ユーザーのログイン制御について①

Posted at

この記事について

ユーザーのログイン制御の方法が色々あるみたいので整理してみる。
本記事では以下の方法を試す。

  • ファイル作成による制御
  • ログインシェル変更による制御

ファイル作成によるログイン制御

以下の方法では、ファイル作成により全ユーザーのログインを拒否する。

  • rootユーザーで/etc/nologin を作成する
[root@localhost ~]# touch /etc/nologin
[root@localhost ~]# ll /etc/nologin
-rw-r--r--. 1 root root 0 Apr 14 16:32 /etc/nologin
  • Teraterm等を用いて、一般ユーザーでサーバーへログインする

  • rootユーザでログを確認する
    一般ユーザーでのログインが拒否されていることを確認できた

Apr 14 16:36:45 localhost.localdomain sshd[2348]: fatal: Access denied for user Kotaro by PAM account configuration [preauth]

参考:PAMについて

ログインシェル変更によるログイン制御

以下の方法では、ログインシェルを変更することにより、一般ユーザ-のログインを拒否する。

/bin/false の場合

  • 特定の一般ユーザーのログインシェルを/bin/falseに変更する
[root@localhost ~]# usermod -s /bin/false Kotaro
[sss_cache] [sysdb_domain_cache_connect] (0x0010): DB version too old [0.23], expected [0.24] for domain implicit_files!
Higher version of database is expected!
In order to upgrade the database, you must run SSSD.
Removing cache files in /var/lib/sss/db should fix the issue, but note that removing cache files will also remove all of your cached credentials.
Could not open available domains
[sss_cache] [sysdb_domain_cache_connect] (0x0010): DB version too old [0.23], expected [0.24] for domain implicit_files!
Higher version of database is expected!
In order to upgrade the database, you must run SSSD.
Removing cache files in /var/lib/sss/db should fix the issue, but note that removing cache files will also remove all of your cached credentials.
Could not open available domains
  • Teraterm等を用いて、ログインシェルを変更した一般ユーザーでサーバーへログインする

  • rootユーザでログを確認する
    当該ユーザーのログインが拒否されていることを確認できた

Apr 14 17:10:41 localhost.localdomain systemd-logind[843]: Removed session 16.
Apr 14 17:10:41 localhost.localdomain systemd-logind[843]: Session 16 logged out. Waiting for processes to exit.
Apr 14 17:10:41 localhost.localdomain systemd[1]: session-16.scope: Succeeded.
Apr 14 17:10:41 localhost.localdomain sshd[2374]: pam_unix(sshd:session): session closed for user Kotaro
  • ログインシェルを変更していない一般ユーザーでログインをする
    image.png

  • ログインすることができた

Last login: Mon Apr 14 17:16:44 2025 from 10.0.15.101
[Kotaro2@localhost ~]$

/sbin/nologin の場合

  • 特定の一般ユーザーのログインシェルを/sbin/nologinに変更する
[root@localhost ~]# usermod -s /sbin/nologin Kotaro
[sss_cache] [sysdb_domain_cache_connect] (0x0010): DB version too old [0.23], expected [0.24] for domain implicit_files!
Higher version of database is expected!
In order to upgrade the database, you must run SSSD.
Removing cache files in /var/lib/sss/db should fix the issue, but note that removing cache files will also remove all of your cached credentials.
Could not open available domains
[sss_cache] [sysdb_domain_cache_connect] (0x0010): DB version too old [0.23], expected [0.24] for domain implicit_files!
Higher version of database is expected!
In order to upgrade the database, you must run SSSD.
Removing cache files in /var/lib/sss/db should fix the issue, but note that removing cache files will also remove all of your cached credentials.
Could not open available domains
  • 当該ユーザーのログインシェルが変更されていることを確認する
[root@localhost ~]# cat /etc/passwd | grep Kotaro
Kotaro:x:1001:1001::/home/Kotaro:/sbin/nologin
  • Teraterm等を用いて、ログインシェルを変更した一般ユーザーでサーバーへログインする

  • rootユーザでログを確認する
    当該ユーザーのログインが拒否されていることを確認できた

Apr 14 17:31:01 localhost.localdomain systemd-logind[843]: Removed session 22.
Apr 14 17:31:01 localhost.localdomain systemd-logind[843]: Session 22 logged out. Waiting for processes to exit.
Apr 14 17:31:01 localhost.localdomain systemd[1]: session-22.scope: Succeeded.
Apr 14 17:31:01 localhost.localdomain sshd[2531]: pam_unix(sshd:session): session closed for user Kotaro
  • ログインシェルを変更していない一般ユーザーでログインをする
    image.png

  • ログインすることができた

Last login: Mon Apr 14 17:18:06 2025 from 10.0.15.101
[Kotaro2@localhost ~]$
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?