シャットダウンが計画されている場合、SSHを介してユーザーにUbuntuサーバーにログインする権限をどのように付与しますか?

シャットダウンが計画されている場合、SSHを介してユーザーにUbuntuサーバーにログインする権限をどのように付与しますか?

crontabでは、次の行を使用して夜間システムの再起動をスケジュールしました。

0 4 * * * /sbin/shutdown -r +5

shutdown -cこの時点でシステムを引き続き実行する必要がある場合は、ログインして再起動をキャンセルできるようにしたいが、4:00以降にsshを試みると、4:00以降に実行するには4:00前にログインする必要があります。 :00:00 と表示されます。スケジュールされたシャットダウン中に特権を持つユーザーのみがログインを許可されることを示すメッセージを表示します。

4:5分再起動をキャンセルするために4:00以降にSSHにアクセスできるユーザー権限をどのように付与しますか?

これを行うにはいくつかの簡単な方法があるようですが、私は初めてLinuxに触れ、現在すべてを学んでいますが、インターネット上で解決策を見つけることができません。

ベストアンサー1

マニュアルshutdownページから抜粋:

   If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that
   further logins shall not be allowed.

Linuxシステムでは、PAMはユーザー認証プロセスを担当します。 PAM構成には、/etc/pam.confおよびがあります/etc/pam.d/*

ファイル(/run/nologin)はPAMモジュールによってチェックされますpam_nologin.so

たとえば、Debian 12では次のようになります。

$ cat /etc/pam.d/login 
#
# The PAM configuration file for the Shadow `login' service
#

# Enforce a minimal delay in case of failure (in microseconds).
# (Replaces the `FAIL_DELAY' setting from login.defs)
# Note that other modules may require another minimal delay. (for example,
# to disable any delay, you should add the nodelay option to pam_unix)
auth       optional   pam_faildelay.so  delay=3000000

# Outputs an issue file prior to each login prompt (Replaces the
# ISSUE_FILE option from login.defs). Uncomment for use
# auth       required   pam_issue.so issue=/etc/issue

# Disallows other than root logins when /etc/nologin exists
# (Replaces the `NOLOGINS_FILE' option from login.defs)
auth       requisite  pam_nologin.so

そのため、認証に必要なpam_nologin.soという行をコメントアウトするだけで十分だと思いました。

おすすめ記事