LoginSignup
0
1

More than 3 years have passed since last update.

MacOSでsudoが遅くなったことの原因

Last updated at Posted at 2019-04-28

概要

「Linuxでパスワードの入力なしでsudoを実行できる」ようにして、スクリプト実行中にパスワード入力をしなくても済むようにしていたので、MacOSでもと思い、トラブルが起きたマシン以外のMacでも設定を行い、うまく行っていた。当該マシンでもと考え、設定を行ったのだが、結果的には他のマシンではしなかった余計な設定をしたためにハマりました。
こんな事をする人は稀でしょうが、同じ状況になった方にお役に立てれば幸いです。

環境

MacOS Mojave, Mac mini(2018)

症状

/etc/sudoersで「パスワード入力なしでsudoを実行する」の設定後に、sudoできるのですが、パスワード入力のプロンプト表示まで数分の時間を要するようになった。後から考えると、設定後の動作確認を行った後に更に変更を追加し、その時には問題ないと考えてチェックを怠たり、気が付いたのが後日だったことが原因だった。

解決

解決の糸口

検索したところ、「mac で sudo時に非常に時間がかかるんだよね」がヒットし、助かりました。/etc/sudoersで、存在しないグループの設定をしてはいけない、ということが書かれていました。macOSの/etc/sudoersは以下のようになっています(関係のある部分のみ抜粋)。

/etc/sudoers
<略>
##
## User privilege specification
##
root ALL=(ALL) ALL
%admin  ALL=(ALL) ALL

## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL) ALL

## Same thing without a password
#%wheel ALL=(ALL) NOPASSWD: ALL

## Uncomment to allow members of group sudo to execute any command
#%sudo  ALL=(ALL) ALL
<略>

トラブルの原因

Debian系ではsudoグループ、RedHat系ではwheelグループがsudoできるグループとして設定されているようですが、MacOSではadminグループです。Debianな私は、当然、sudoというグループが存在すると考えて、不注意にも以下のようにしてしまいました。当然、sudoグループの存在を確認していませんでしたが、無くても問題ないだろうと考えたのが浅はかでした。

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL

## Uncomment to allow members of group sudo to execute any command
%sudo  ALL=(ALL) ALL

MacOSでは、管理者はadminグループに設定されるようですので、本来は、以下のようにすべきです。(私は別な方法にしています。後述)

## Same thing without a password
#%wheel ALL=(ALL) NOPASSWD: ALL
%admin ALL=(ALL) NOPASSWD: ALL

私の設定

私は、CentOSと同様に自分をwheelグループにしています。

%wheel ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: ALL

しかし、この後でMacOSには、usermodがないことに気づきました。以下のように行います。
wheelグループへの追加

sudo dscl . append /Groups/wheel GroupMembership user_name

wheelグループからの削除は

sudo dscl . delete /Groups/wheel GroupMembership user_id

/etc/groupでも登録は確認できますが、wheelグループに登録されたユーザを表示は以下のようにします。

dscl . read /Groups/wheel

sudoに時間がかかるのは、死活問題であることを痛感しました。

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